Class or struct representing a calendar date. More...
Public Member Functions | |
| int_year | year () const |
| Get the year of a Date. More... | |
| int_month | month () const |
| Get the month of a Date (1 to 12, inclusive). More... | |
| int_day | day () const |
| Get the day of month of a Date (1 to 31, inclusive). More... | |
| int_day_of_year | day_of_year () const |
| Get the day of the year of a Date (1 to 366, inclusive). More... | |
| PresentWeekYear | week_of_year () const |
| Get the week of the year of a Date (1 to 53, inclusive), and the year corresponding to that week. More... | |
| int_day_of_week | day_of_week () const |
| Get the day of the week of a Date (1 to 7, inclusive, with 1 being Monday, 2 being Tuesday, ..., 6 being Saturday, and 7 being Sunday). More... | |
| DayDelta | difference (const Date &other) const |
| Get the difference between two Date instances. More... | |
| DayDelta | absolute_difference (const Date &other) const |
| Get the absolute difference between two Date instances. More... | |
| Date & | operator+= (const DayDelta &delta) |
| Add a DayDelta to a Date. More... | |
| Date & | operator+= (const MonthDelta &delta) |
| Add a MonthDelta to a Date. More... | |
| Date & | operator-= (const DayDelta &delta) |
| Subtract a DayDelta from a Date. More... | |
| Date & | operator-= (const MonthDelta &delta) |
| Subtract a MonthDelta from a Date. More... | |
Static Public Member Functions | |
| static Date | create (int_year year) |
| Create a new Date based on a year. More... | |
| static Date | create (int_year year, int_month month) |
| Create a new Date based on a year and a month. More... | |
| static Date | create (int_year year, int_month month, int_day day) |
| Create a new Date based on a year, a month, and a day. More... | |
| static Date | from_year_day (int_year year, int_day_of_year day_of_year) |
| Create a new Date based on a year and the day of that year. More... | |
| static Date | from_year_week_day (int_year year, int_week_of_year week_of_year, int_day_of_week day_of_week) |
| Create a new Date based on a year, a week of that year, and a day of the week. More... | |
| static short | compare (const Date &lhs, const Date &rhs) |
| Compare two Date instances. More... | |
Public Attributes | |
| present_bool | has_error |
| This will be true if there were any errors when creating this Date. More... | |
| struct { | |
| unsigned int month_out_of_range: 1 | |
| unsigned int day_out_of_range: 1 | |
| unsigned int week_of_year_out_of_range: 1 | |
| unsigned int day_of_week_out_of_range: 1 | |
| } | errors |
| If there were any errors when creating this Date, then one or more of these fields will be set. More... | |
| struct PresentDateData | data_ |
Friends | |
| const Date | operator+ (const Date &lhs, const DayDelta &rhs) |
| const Date | operator+ (const DayDelta &lhs, const Date &rhs) |
| const Date | operator+ (const Date &lhs, const MonthDelta &rhs) |
| const Date | operator+ (const MonthDelta &lhs, const Date &rhs) |
| const Date | operator- (const Date &lhs, const DayDelta &rhs) |
| const Date | operator- (const Date &lhs, const MonthDelta &rhs) |
| bool | operator== (const Date &lhs, const Date &rhs) |
| Determine whether two Date instances are equal (lhs == rhs). More... | |
| bool | operator!= (const Date &lhs, const Date &rhs) |
| bool | operator< (const Date &lhs, const Date &rhs) |
| Determine whether a Date is earlier than another Date (lhs < rhs). More... | |
| bool | operator<= (const Date &lhs, const Date &rhs) |
| Determine whether a Date is earlier than or the same as another Date (lhs <= rhs). More... | |
| bool | operator> (const Date &lhs, const Date &rhs) |
| Determine whether a Date is later than another Date (lhs > rhs). More... | |
| bool | operator>= (const Date &lhs, const Date &rhs) |
| Determine whether a Date is later than or the same as another Date (lhs >= rhs). More... | |
Class or struct representing a calendar date.
This includes a year, a month, and a day. There is no time-of-day stored with the date, nor a time zone.
Create a new Date based on a year.
The month and day will be set to January 1.
| year | The year. |
Create a new Date based on a year and a month.
The day will be set to the first of the month.
If the month is out of range, the Date will have has_error and errors set.
has_error field on the returned struct is true.If has_error is true, then at least one of the fields in the errors struct will also be true.
| year | The year. |
| month | The month of the year (1 to 12, inclusive). |
Create a new Date based on a year, a month, and a day.
If the month or the day is out of range, the Date will have has_error and errors set.
has_error field on the returned struct is true.If has_error is true, then at least one of the fields in the errors struct will also be true.
| year | The year. |
| month | The month of the year (1 to 12, inclusive). |
| day | The day of the month (1 to either 28, 29, 30, or 31, inclusive, depending on the month). |
|
static |
Create a new Date based on a year and the day of that year.
| year | The year. |
| day_of_year | The day of the year. |
|
static |
Create a new Date based on a year, a week of that year, and a day of the week.
Weeks of the year are determined in the same way that the ISO8601 standard defines week numbers. For more info, see: https://en.wikipedia.org/wiki/ISO_week_date
If the week of the year or the day of the week is out of range, the Date will have has_error and errors set.
has_error field on the returned struct is true.If has_error is true, then at least one of the fields in the errors struct will also be true.
| year | The year. |
| week_of_year | The week of the year (1 to 52 or 53, inclusive, depending on the year). |
| day_of_week | The day of the week (1 to 7, inclusive). See present/internal/types.h for constants for each day of the week. |
| int_day_of_year Date::day_of_year | ( | ) | const |
Get the day of the year of a Date (1 to 366, inclusive).
| PresentWeekYear Date::week_of_year | ( | ) | const |
Get the week of the year of a Date (1 to 53, inclusive), and the year corresponding to that week.
| int_day_of_week Date::day_of_week | ( | ) | const |
Get the day of the week of a Date (1 to 7, inclusive, with 1 being Monday, 2 being Tuesday, ..., 6 being Saturday, and 7 being Sunday).
Get the difference between two Date instances.
Get the absolute difference between two Date instances.
| Date& Date::operator+= | ( | const MonthDelta & | delta | ) |
Add a MonthDelta to a Date.
| Date& Date::operator-= | ( | const MonthDelta & | delta | ) |
Subtract a MonthDelta from a Date.
Compare two Date instances.
|
friend |
|
friend |
|
friend |
Determine whether two Date instances are equal (lhs == rhs).
| present_bool Date::has_error |
This will be true if there were any errors when creating this Date.
For more details about the errors that occurred, see errors. For more details about the errors that occurred, see errors.
This field should be treated as read-only; DO NOT modify its contents!
| unsigned int Date::month_out_of_range |
| unsigned int Date::day_out_of_range |
| unsigned int Date::week_of_year_out_of_range |
| unsigned int Date::day_of_week_out_of_range |
| struct { ... } Date::errors |
If there were any errors when creating this Date, then one or more of these fields will be set.
To quickly check if any error occurred, see has_error. To quickly check if any error occurred, see has_error.
These fields should be treated as read-only; DO NOT modify their contents!
| struct PresentDateData Date::data_ |