1 #ifndef MSP_TIME_DATETIME_H_
2 #define MSP_TIME_DATETIME_H_
15 Provides handling of arbitary dates and times. Can represent a moment of time
16 in the range of about ±2.1×10⁹ years. It can also be formatted into a string
17 for presentation to the user.
19 Due to the complex internal representation, arithmetic operations on a DateTime
20 are relatively slow. For purposes of internal scheduling in a program, a
21 TimeStamp is a better choice.
27 unsigned char month = 1;
28 unsigned char mday = 1;
29 unsigned char hour = 0;
30 unsigned char minute = 0;
31 unsigned char second = 0;
36 DateTime(const TimeStamp &);
37 DateTime(const TimeStamp &, const TimeZone &);
38 DateTime(int, unsigned char, unsigned char);
39 DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
40 DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned);
42 static DateTime parse_rfc3339(const std::string &);
44 int get_year() const { return year; }
45 unsigned char get_month() const { return month; }
46 unsigned char get_mday() const { return mday; }
47 unsigned char get_hour() const { return hour; }
48 unsigned char get_minute() const { return minute; }
49 unsigned char get_second() const { return second; }
50 unsigned get_usec() const { return usec; }
53 void set_timezone(const TimeZone &);
54 void convert_timezone(const TimeZone &);
56 DateTime operator+(const TimeDelta &) const;
57 DateTime &operator+=(const TimeDelta &);
58 DateTime operator-(const TimeDelta &) const;
59 DateTime &operator-=(const TimeDelta &);
61 bool operator==(const DateTime &d) const { return cmp(d)==0; }
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; }
68 int cmp(const DateTime &) const;
69 TimeStamp get_timestamp() const;
70 std::string format(const std::string &) const;
71 std::string format_rfc3339() const;
74 void add_raw(RawTime);
78 inline void operator<<(LexicalConverter &c, const DateTime &d)
79 { c.result(d.format_rfc3339()); }
81 inline void operator>>(const LexicalConverter &c, DateTime &d)
82 { d = DateTime::parse_rfc3339(c.get()); }