#include <Pt/DateTime.h>
Combined Date and Time value. More...
Public Member Functions | |
| DateTime () | |
| Default Constructor. | |
| DateTime (int y, unsigned mon, unsigned d, unsigned h=0, unsigned min=0, unsigned s=0, unsigned ms=0) | |
| Construct to date and time. | |
| DateTime (const DateTime &dateTime) | |
| Copy Constructor. | |
| DateTime & | operator= (const DateTime &dateTime) |
| Assignment operator. | |
| void | set (int year, unsigned month, unsigned day, unsigned hour=0, unsigned min=0, unsigned sec=0, unsigned msec=0) |
| Sets the date and time. | |
| void | get (int &year, unsigned &month, unsigned &day, unsigned &hour, unsigned &min, unsigned &sec, unsigned &msec) const |
| Gets the date and time. | |
| const Date & | date () const |
| Gets the date. | |
| Date & | date () |
| Gets the date. | |
| DateTime & | setDate (const Date &dt) |
| Sets the date. | |
| const Time & | time () const |
| Gets the time. | |
| Time & | time () |
| Gets the time. | |
| DateTime & | setTime (const Time &t) |
| Sets the time. | |
| 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 | hour () const |
| Returns the hour-part of the Time. | |
| unsigned | minute () const |
| Returns the minute-part of the Time. | |
| unsigned | second () const |
| Returns the second-part of the Time. | |
| unsigned | msec () const |
| Returns the millisecond-part of the Time. | |
| std::string | toIsoString () const |
| Returns the date and time in ISO-format. | |
| std::string | toIsoString (int *utcOffset) const |
| Returns the date and time in ISO-format. | |
| DateTime & | operator+= (const Timespan &ts) |
| Assignment by sum operator. | |
| DateTime & | operator-= (const Timespan &ts) |
| Assignment by difference operator. | |
Static Public Member Functions | |
| static DateTime | fromIsoString (const std::string &s) |
| Interprets a string as a date and time in ISO-format. | |
| static DateTime | fromIsoString (const std::string &s, int *utcOffset) |
| Interprets a string as a date and time in ISO-format. | |
| static bool | isValid (int year, unsigned month, unsigned day, unsigned hour, unsigned minute, unsigned second, unsigned msec) |
| Returns true if values are a valid date and time. | |
Related Functions | |
| void | operator>>= (const SerializationInfo &si, DateTime &dt) |
| Deserialize a DateTime. | |
| void | operator<<= (SerializationInfo &si, const DateTime &dt) |
| Serialize a DateTime. | |
| DateTime | operator+ (const DateTime &dt, const Timespan &ts) |
| Add a timespan. | |
| Timespan | operator- (const DateTime &first, const DateTime &second) |
| Subtract two DateTimes. | |
| DateTime | operator- (const DateTime &dt, const Timespan &ts) |
| Subtract a timespan. | |
| bool | operator< (const DateTime &a, const DateTime &b) |
| Less-than comparison operator. | |
| bool | operator<= (const DateTime &a, const DateTime &b) |
| Less-than-equal comparison operator. | |
| bool | operator> (const DateTime &a, const DateTime &b) |
| Greater-than comparison operator. | |
| bool | operator>= (const DateTime &a, const DateTime &b) |
| Greater-than-equal comparison operator. | |
| bool | operator== (const DateTime &a, const DateTime &b) |
| Returns true if equal. | |
| bool | operator!= (const DateTime &a, const DateTime &b) |
| Returns true if not equal. | |
Pt::DateTime combines a Pt::Date and a Pt::Time object into one instance. It can either be constructed from the corrsponding numeric values or a string in ISO format. The date and time parts can be accessed with date() and time(). When two DateTimes are compared, one is considered less, if its date is earlier or if the time is earlier in case of equal dates. A Pt::Timespan can be added or subtracted from a DateTime and this is also the result when two DateTimes are subtracted. To avoid the exceptions thrown by the underlying time and date, isValid() can be used to check numeric date and time values.