49 [[nodiscard]]
const char *
what() const noexcept override;
55 std::
string m_message;
93 Date(
int day,
int month,
int year);
104 explicit Date(std::string_view str);
112 explicit Date(std::time_t timer);
118 [[nodiscard]]
int Day() const noexcept;
121 [[nodiscard]]
int Month() const noexcept;
124 [[nodiscard]]
int Year() const noexcept;
208 [[nodiscard]] std::strong_ordering operator<=>(const
Date &rhs) const noexcept;
211 [[nodiscard]]
bool operator==(const
Date &rhs) const noexcept = default;
218 [[nodiscard]] static
bool IsLeap(
int year);
Reason GetReason() const noexcept
Returns the exception reason.
DateError(Reason reason, std::string message)
Constructs a DateError from a reason and an error message.
Reason
Indicates the reason for a DateError exception.
Definition date.h:29
@ INVALID_DATE
Invalid day/month/year combination.
Definition date.h:33
@ INVALID_FORMAT
Invalid date string format.
Definition date.h:34
@ INVALID_MONTH
Month is out of valid range [1, 12].
Definition date.h:31
@ EPOCH_FAILURE
Failed time_t conversion.
Definition date.h:36
@ SYSTEM_FAILURE
Failed system operation.
Definition date.h:38
@ INVALID_DAY
Day is out of valid range [1, 31].
Definition date.h:30
@ OUT_OF_RANGE
Resulting date is out of [01/01/MIN_YEAR, 31/12/MAX_YEAR].
Definition date.h:35
@ INVALID_YEAR
Year is out of valid range [MIN_YEAR, MAX_YEAR].
Definition date.h:32
@ LOGIC_ERROR
Logically invalid argument.
Definition date.h:37
const char * what() const noexcept override
Returns the exception message.
static bool IsLeap(int year)
Queries whether a year is leap.
int Month() const noexcept
Returns the month.
Date(int day, int month, int year)
Constructs a date from a day, a month and a year.
int operator-(const Date &lhs, const Date &rhs) noexcept
Returns the number of days between two dates.
int Year() const noexcept
Returns the year.
int Day() const noexcept
Returns the day.
ISOWeek WeekOfYear() const noexcept
Returns the week of year according to ISO 8601.
Date(std::string_view str)
Constructs a date by parsing a string in dd/mm/yyyy format.
static constexpr int MAX_YEAR
Maximum supported year.
Definition date.h:23
Date operator+(const Date &d, int days)
Returns the result of moving a date forward by the given number of days.
Date()=default
Constructs a date set to 01/01/1900.
int DayOfYear() const noexcept
Returns the day of year.
static Date RandomDate(int minYear=MIN_YEAR, int maxYear=Today().Year())
Returns a random date within the given year range.
Date operator-(const Date &d, int days)
Returns the result of moving a date back by the given number of days.
static Date Today()
Returns today's date.
std::istream & operator>>(std::istream &is, Date &d)
Extracts a date in dd/mm/yyyy format from an input stream.
Date(std::time_t timer)
Constructs a date from a time since epoch.
Date operator+(int days, const Date &d)
Returns the result of moving a date forward by the given number of days.
Date(std::nullptr_t)=delete
Prevents construction from nullptr.
int Weekday() const noexcept
Returns the weekday.
bool operator==(const Date &rhs) const noexcept=default
Checks two dates for equality.
static constexpr int MIN_YEAR
Minimum supported year.
Definition date.h:22
std::ostream & operator<<(std::ostream &os, const Date &d)
Inserts a date into an output stream (e.g. 12 December 2024 Thursday).
ISO 8601 week date.
Definition date.h:59
int year
ISO week-numbering year.
Definition date.h:60
int week
ISO week number [1, 53].
Definition date.h:61