#include <Pt/Date.h>
Date expressed in year, month, and day. More...
Public Member Functions | |
| Date () | |
| Default constructor. More... | |
| Date (const Date &date) | |
| Copy constructor. | |
| Date (int y, unsigned m, unsigned d) | |
| Constructs a Date from given values. More... | |
| Date (unsigned julianDays) | |
| Constructs a Date from a julian day. | |
| Date & | operator= (const Date &date) |
| Assignment operator. | |
| void | setJulian (unsigned d) |
| Sets the Date to a julian day. | |
| unsigned | julian () const |
| Returns the Date as a julian day. | |
| void | set (int y, unsigned m, unsigned d) |
| Sets the date to a year, month and day. More... | |
| void | get (int &year, unsigned &month, unsigned &day) const |
| Gets the year, month and day. | |
| unsigned | day () const |
| Returns the day-part of the date. | |
| unsigned | month () const |
| Returns the month-part of the date. | |
| int | year () const |
| Returns the year-part of the date. | |
| unsigned | dayOfWeek () const |
| Return day of the week, starting with sunday. | |
| unsigned | daysInMonth () const |
| Returns the days of the month of the date. | |
| unsigned | dayOfYear () const |
| Returns the day of the year. | |
| bool | isLeapYear () const |
| Returns true if the date is in a leap year. | |
| void | addDays (int n) |
| Adds n days to the date. | |
| void | addMonths (int n) |
| Adds n months to the date. | |
| void | addYears (int n) |
| Adds n years to the date. | |
| std::string | toIsoString () const |
| Returns the date in ISO-format. More... | |
| Date & | operator+= (int days) |
| Add days to the date. | |
| Date & | operator-= (int days) |
| Substract days from the date. | |
| Date & | operator++ () |
| Increments the date by one day. | |
| Date & | operator-- () |
| Decrements the date by one day. | |
Static Public Member Functions | |
| static Date | fromIsoString (const std::string &s) |
| Interprets a string as a date-string in ISO-format. More... | |
| static bool | isValid (int y, int m, int d) |
| Returns true if values describe a valid date. | |
| static bool | isLeapYear (int year) |
| Returns true if the year is in a leap year. | |
Static Public Attributes | |
| static const unsigned | DaysPerYear = 365 |
| The number of days of an ordinary year. | |
| static const unsigned | DaysPerLeapYear = 366 |
| The number of days of a leap year. | |
| static const unsigned | DaysOfJan = 31 |
| The number of days of a January. | |
| static const unsigned | DaysOfFeb = 28 |
| The number of days of a February. | |
| static const unsigned | DaysOfLeapFeb = 29 |
| The number of days of a February in a leap year. | |
| static const unsigned | DaysOfMar = 31 |
| The number of days of a March. | |
| static const unsigned | DaysOfApr = 30 |
| The number of days of a April. | |
| static const unsigned | DaysOfMay = 31 |
| The number of days of a May. | |
| static const unsigned | DaysOfJun = 30 |
| The number of days of a June. | |
| static const unsigned | DaysOfJul = 31 |
| The number of days of a July. | |
| static const unsigned | DaysOfAug = 31 |
| The number of days of a August. | |
| static const unsigned | DaysOfSep = 30 |
| The number of days of a September. | |
| static const unsigned | DaysOfOct = 31 |
| The number of days of a October. | |
| static const unsigned | DaysOfNov = 30 |
| The number of days of a November. | |
| static const unsigned | DaysOfDec = 31 |
| The number of days of a December. | |
Related Functions | |
| void | operator>>= (const SerializationInfo &si, Date &date) |
| Deserialize a date. | |
| void | operator<<= (SerializationInfo &si, const Date &date) |
| Serialize a date. | |
| bool | operator== (const Date &a, const Date &b) |
| Returns true if the dates are equal. | |
| bool | operator!= (const Date &a, const Date &b) |
| Returns true if the dates are not equal. | |
| bool | operator< (const Date &a, const Date &b) |
| Less-than comparison operator. | |
| bool | operator<= (const Date &a, const Date &b) |
| Less-than-equal comparison operator. | |
| bool | operator> (const Date &a, const Date &b) |
| Greater-than comparison operator. | |
| bool | operator>= (const Date &a, const Date &b) |
| Greater-than-equal comparison operator. | |
| Date | operator+ (const Date &d, int days) |
| Add days to a date. | |
| Date | operator+ (int days, const Date &d) |
| Add days to a date. | |
| int | operator- (const Date &a, const Date &b) |
| Subtract two dates. | |
Pt::Date is an easy way to handle calendar dates. It can be constructed from the days, month and year components or from an ISO string using fromIsoString(). The date components can be accessed with day(), month() and year(). Once a Date object is created, calendar information can be accessed, for example with dayOfYear(), dayOfWeek() or isLeapYear(). Dates can be compared and a Date is considered less if it is earlier than another Date. It is also possible to add or subtract days from a Date, which yields a new date or modifies it. Dates can be subtracted, which yields the number of days between them, as shown in the next example:
Pt::InvalidDate is thrown, if a date could not be constructed, for example if one of the date components is out of range. To avoid an exception, date components can be validated with isValid().
| Date | ( | ) |
The default constructed date is undefined.
| Date | ( | int | y, |
| unsigned | m, | ||
| unsigned | d | ||
| ) |
Sets the date to a new year, month and day. InvalidDate is thrown if any of the values is out of range
| void set | ( | int | y, |
| unsigned | m, | ||
| unsigned | d | ||
| ) |
Sets the date to a new year, month and day. InvalidDate is thrown if any of the values is out of range
| std::string toIsoString | ( | ) | const |
Converts the date in ISO-format (yyyy-mm-dd).