1 #ifndef MSP_TIME_DATETIME_H_
2 #define MSP_TIME_DATETIME_H_
5 #include <msp/core/mspcore_api.h>
16 Provides handling of arbitary dates and times. Can represent a moment of time
17 in the range of about ±2.1×10⁹ years. It can also be formatted into a string
18 for presentation to the user.
20 Due to the complex internal representation, arithmetic operations on a DateTime
21 are relatively slow. For purposes of internal scheduling in a program, a
22 TimeStamp is a better choice.
24 class MSPCORE_API DateTime
28 unsigned char month = 1;
29 unsigned char mday = 1;
30 unsigned char hour = 0;
31 unsigned char minute = 0;
32 unsigned char second = 0;
37 DateTime(const TimeStamp &);
38 DateTime(const TimeStamp &, const TimeZone &);
39 DateTime(int, unsigned char, unsigned char);
40 DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
41 DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned);
43 static DateTime parse_rfc3339(const std::string &);
45 int get_year() const { return year; }
46 unsigned char get_month() const { return month; }
47 unsigned char get_mday() const { return mday; }
48 unsigned char get_hour() const { return hour; }
49 unsigned char get_minute() const { return minute; }
50 unsigned char get_second() const { return second; }
51 unsigned get_usec() const { return usec; }
54 void set_timezone(const TimeZone &);
55 void convert_timezone(const TimeZone &);
57 DateTime operator+(const TimeDelta &) const;
58 DateTime &operator+=(const TimeDelta &);
59 DateTime operator-(const TimeDelta &) const;
60 DateTime &operator-=(const TimeDelta &);
62 bool operator==(const DateTime &d) const { return cmp(d)==0; }
63 bool operator!=(const DateTime &d) const { return cmp(d)!=0; }
64 bool operator<(const DateTime &d) const { return cmp(d)<0; }
65 bool operator<=(const DateTime &d) const { return cmp(d)<=0; }
66 bool operator>(const DateTime &d) const { return cmp(d)>0; }
67 bool operator>=(const DateTime &d) const { return cmp(d)>=0; }
69 int cmp(const DateTime &) const;
70 TimeStamp get_timestamp() const;
71 std::string format(const std::string &) const;
72 std::string format_rfc3339() const;
75 void add_raw(RawTime);
79 inline void operator<<(LexicalConverter &c, const DateTime &d)
80 { c.result(d.format_rfc3339()); }
82 inline void operator>>(const LexicalConverter &c, DateTime &d)
83 { d = DateTime::parse_rfc3339(c.get()); }