Represents a calendar date.
More...
#include <date.h>
|
| | Date ()=default |
| | Constructs a date set to 01/01/1900.
|
| | Date (int day, int month, int year) |
| | Constructs a date from a day, a month and a year.
|
| | Date (std::string_view str) |
| | Constructs a date by parsing a string in dd/mm/yyyy format.
|
| | Date (std::time_t timer) |
| | Constructs a date from a time since epoch.
|
| | Date (std::nullptr_t)=delete |
| | Prevents construction from nullptr.
|
| int | Day () const noexcept |
| | Returns the day.
|
| int | Month () const noexcept |
| | Returns the month.
|
| int | Year () const noexcept |
| | Returns the year.
|
| int | DayOfYear () const noexcept |
| | Returns the day of year.
|
| int | Weekday () const noexcept |
| | Returns the weekday.
|
| ISOWeek | WeekOfYear () const noexcept |
| | Returns the week of year according to ISO 8601.
|
| Date & | Day (int day) & |
| | Sets the day.
|
| Date & | Month (int month) & |
| | Sets the month.
|
| Date & | Year (int year) & |
| | Sets the year.
|
| Date & | operator+= (int days) & |
| | Moves the date forward by the given number of days.
|
| Date & | operator-= (int days) & |
| | Moves the date back by the given number of days.
|
| Date & | operator++ () & |
| | Increments the date by one day.
|
| Date | operator++ (int) & |
| | Increments the date by one day.
|
| Date & | operator-- () & |
| | Decrements the date by one day.
|
| Date | operator-- (int) & |
| | Decrements the date by one day.
|
| std::strong_ordering | operator<=> (const Date &rhs) const noexcept |
| | Compares two dates chronologically.
|
| bool | operator== (const Date &rhs) const noexcept=default |
| | Checks two dates for equality.
|
|
| static constexpr int | MIN_YEAR { 1900 } |
| | Minimum supported year.
|
| static constexpr int | MAX_YEAR { 9999 } |
| | Maximum supported year.
|
|
(Note that these are not member symbols.)
|
| Date | operator+ (const Date &d, int days) |
| | Returns the result of moving a date forward by the given number of days.
|
| Date | operator+ (int days, const Date &d) |
| | Returns the result of moving a date forward by the given number of days.
|
| Date | operator- (const Date &d, int days) |
| | Returns the result of moving a date back by the given number of days.
|
| int | operator- (const Date &lhs, const Date &rhs) noexcept |
| | Returns the number of days between two dates.
|
| std::istream & | operator>> (std::istream &is, Date &d) |
| | Extracts a date in dd/mm/yyyy format from an input stream.
|
| std::ostream & | operator<< (std::ostream &os, const Date &d) |
| | Inserts a date into an output stream (e.g. 12 December 2024 Thursday).
|
Represents a calendar date.
◆ Date() [1/5]
Constructs a date set to 01/01/1900.
◆ Date() [2/5]
| cgr::Date::Date |
( |
int | day, |
|
|
int | month, |
|
|
int | year ) |
Constructs a date from a day, a month and a year.
- Parameters
-
| day | The day. |
| month | The month. |
| year | The year. |
- Exceptions
-
| DateError | If day is out of valid range [1, 31] (Reason::INVALID_DAY). |
| DateError | If month is out of valid range [1, 12] (Reason::INVALID_MONTH). |
| DateError | If year is out of valid range [MIN_YEAR, MAX_YEAR] (Reason::INVALID_YEAR). |
| DateError | If day/month/year combination is invalid (Reason::INVALID_DATE). |
◆ Date() [3/5]
| cgr::Date::Date |
( |
std::string_view | str | ) |
|
|
explicit |
Constructs a date by parsing a string in dd/mm/yyyy format.
- Parameters
-
- Exceptions
-
| DateError | If str does not match the dd/mm/yyyy format (Reason::INVALID_FORMAT). |
| DateError | If day is out of valid range [1, 31] (Reason::INVALID_DAY). |
| DateError | If month is out of valid range [1, 12] (Reason::INVALID_MONTH). |
| DateError | If year is out of valid range [MIN_YEAR, MAX_YEAR] (Reason::INVALID_YEAR). |
| DateError | If day/month/year combination is invalid (Reason::INVALID_DATE). |
◆ Date() [4/5]
| cgr::Date::Date |
( |
std::time_t | timer | ) |
|
|
explicit |
Constructs a date from a time since epoch.
- Parameters
-
| timer | The time since epoch. |
- Exceptions
-
| DateError | If conversion from the time since epoch to a date fails (Reason::EPOCH_FAILURE). |
| DateError | If the resulting date is out of [01/01/MIN_YEAR, 31/12/MAX_YEAR] (Reason::OUT_OF_RANGE). |
◆ Date() [5/5]
| cgr::Date::Date |
( |
std::nullptr_t | | ) |
|
|
delete |
Prevents construction from nullptr.
◆ Today()
| Date cgr::Date::Today |
( |
| ) |
|
|
staticnodiscard |
Returns today's date.
- Exceptions
-
| DateError | If today's date cannot be obtained (Reason::SYSTEM_FAILURE). |
◆ RandomDate()
Returns a random date within the given year range.
- Parameters
-
| minYear | The minimum year. |
| maxYear | The maximum year. |
- Exceptions
-
| DateError | If minYear or maxYear is out of [MIN_YEAR, MAX_YEAR] (Reason::INVALID_YEAR). |
| DateError | If minYear > maxYear (Reason::LOGIC_ERROR). |
◆ Day() [1/2]
| int cgr::Date::Day |
( |
| ) |
const |
|
nodiscardnoexcept |
◆ Month() [1/2]
| int cgr::Date::Month |
( |
| ) |
const |
|
nodiscardnoexcept |
◆ Year() [1/2]
| int cgr::Date::Year |
( |
| ) |
const |
|
nodiscardnoexcept |
◆ DayOfYear()
| int cgr::Date::DayOfYear |
( |
| ) |
const |
|
nodiscardnoexcept |
◆ Weekday()
| int cgr::Date::Weekday |
( |
| ) |
const |
|
nodiscardnoexcept |
◆ WeekOfYear()
| ISOWeek cgr::Date::WeekOfYear |
( |
| ) |
const |
|
nodiscardnoexcept |
Returns the week of year according to ISO 8601.
◆ Day() [2/2]
| Date & cgr::Date::Day |
( |
int | day | ) |
& |
Sets the day.
- Parameters
-
- Exceptions
-
| DateError | If day is out of valid range [1, 31] (Reason::INVALID_DAY). |
- Note
- Strong exception guarantee.
◆ Month() [2/2]
| Date & cgr::Date::Month |
( |
int | month | ) |
& |
Sets the month.
- Parameters
-
- Exceptions
-
| DateError | If month is out of valid range [1, 12] (Reason::INVALID_MONTH). |
- Note
- Strong exception guarantee.
◆ Year() [2/2]
| Date & cgr::Date::Year |
( |
int | year | ) |
& |
Sets the year.
- Parameters
-
- Exceptions
-
| DateError | If year is out of valid range [MIN_YEAR, MAX_YEAR] (Reason::INVALID_YEAR). |
- Note
- Strong exception guarantee.
◆ operator+=()
| Date & cgr::Date::operator+= |
( |
int | days | ) |
& |
Moves the date forward by the given number of days.
- Parameters
-
- Exceptions
-
| DateError | If days is negative (Reason::LOGIC_ERROR). |
| DateError | If the resulting date exceeds 31/12/MAX_YEAR (Reason::OUT_OF_RANGE). |
- Note
- Strong exception guarantee.
◆ operator-=()
| Date & cgr::Date::operator-= |
( |
int | days | ) |
& |
Moves the date back by the given number of days.
- Parameters
-
- Exceptions
-
| DateError | If days is negative (Reason::LOGIC_ERROR). |
| DateError | If the resulting date falls below 01/01/MIN_YEAR (Reason::OUT_OF_RANGE). |
- Note
- Strong exception guarantee.
◆ operator++() [1/2]
| Date & cgr::Date::operator++ |
( |
| ) |
& |
Increments the date by one day.
- Exceptions
-
| DateError | If the resulting date exceeds 31/12/MAX_YEAR (Reason::OUT_OF_RANGE). |
- Note
- Strong exception guarantee.
◆ operator++() [2/2]
| Date cgr::Date::operator++ |
( |
int | | ) |
& |
Increments the date by one day.
- Returns
- The date before the increment.
- Exceptions
-
| DateError | If the resulting date exceeds 31/12/MAX_YEAR (Reason::OUT_OF_RANGE). |
- Note
- Strong exception guarantee.
◆ operator--() [1/2]
| Date & cgr::Date::operator-- |
( |
| ) |
& |
Decrements the date by one day.
- Exceptions
-
| DateError | If the resulting date falls below 01/01/MIN_YEAR (Reason::OUT_OF_RANGE). |
- Note
- Strong exception guarantee.
◆ operator--() [2/2]
| Date cgr::Date::operator-- |
( |
int | | ) |
& |
Decrements the date by one day.
- Returns
- The date before the decrement.
- Exceptions
-
| DateError | If the resulting date falls below 01/01/MIN_YEAR (Reason::OUT_OF_RANGE). |
- Note
- Strong exception guarantee.
◆ operator<=>()
| std::strong_ordering cgr::Date::operator<=> |
( |
const Date & | rhs | ) |
const |
|
nodiscardnoexcept |
Compares two dates chronologically.
◆ operator==()
| bool cgr::Date::operator== |
( |
const Date & | rhs | ) |
const |
|
nodiscarddefaultnoexcept |
Checks two dates for equality.
◆ IsLeap()
| bool cgr::Date::IsLeap |
( |
int | year | ) |
|
|
staticnodiscard |
Queries whether a year is leap.
- Parameters
-
- Exceptions
-
| DateError | If the year is out of range [MIN_YEAR, MAX_YEAR] (Reason::INVALID_YEAR). |
◆ operator+() [1/2]
| Date operator+ |
( |
const Date & | d, |
|
|
int | days ) |
|
related |
Returns the result of moving a date forward by the given number of days.
- Parameters
-
| d | The date. |
| days | The number of days. |
- Exceptions
-
| DateError | If days is negative (Reason::LOGIC_ERROR). |
| DateError | If the resulting date exceeds 31/12/MAX_YEAR (Reason::OUT_OF_RANGE). |
◆ operator+() [2/2]
| Date operator+ |
( |
int | days, |
|
|
const Date & | d ) |
|
related |
Returns the result of moving a date forward by the given number of days.
- Parameters
-
| days | The number of days. |
| d | The date. |
- Exceptions
-
| DateError | If days is negative (Reason::LOGIC_ERROR). |
| DateError | If the resulting date exceeds 31/12/MAX_YEAR (Reason::OUT_OF_RANGE). |
◆ operator-() [1/2]
| Date operator- |
( |
const Date & | d, |
|
|
int | days ) |
|
related |
Returns the result of moving a date back by the given number of days.
- Parameters
-
| d | The date. |
| days | The number of days. |
- Exceptions
-
| DateError | If days is negative (Reason::LOGIC_ERROR). |
| DateError | If the resulting date falls below 01/01/MIN_YEAR (Reason::OUT_OF_RANGE). |
◆ operator-() [2/2]
| int operator- |
( |
const Date & | lhs, |
|
|
const Date & | rhs ) |
|
related |
Returns the number of days between two dates.
◆ operator>>()
| std::istream & operator>> |
( |
std::istream & | is, |
|
|
Date & | d ) |
|
related |
Extracts a date in dd/mm/yyyy format from an input stream.
◆ operator<<()
| std::ostream & operator<< |
( |
std::ostream & | os, |
|
|
const Date & | d ) |
|
related |
Inserts a date into an output stream (e.g. 12 December 2024 Thursday).
◆ MIN_YEAR
| int cgr::Date::MIN_YEAR { 1900 } |
|
staticconstexpr |
◆ MAX_YEAR
| int cgr::Date::MAX_YEAR { 9999 } |
|
staticconstexpr |
The documentation for this class was generated from the following file: