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.
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 void init(const TimeStamp &);
43 void init(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned);
46 static DateTime parse_rfc3339(const std::string &);
48 int get_year() const { return year; }
49 unsigned char get_month() const { return month; }
50 unsigned char get_mday() const { return mday; }
51 unsigned char get_hour() const { return hour; }
52 unsigned char get_minute() const { return minute; }
53 unsigned char get_second() const { return second; }
54 unsigned get_usec() const { return usec; }
57 void set_timezone(const TimeZone &);
58 void convert_timezone(const TimeZone &);
60 DateTime operator+(const TimeDelta &) const;
61 DateTime &operator+=(const TimeDelta &);
62 DateTime operator-(const TimeDelta &) const;
63 DateTime &operator-=(const TimeDelta &);
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; }
68 bool operator<=(const DateTime &d) const { return cmp(d)<=0; }
69 bool operator>(const DateTime &d) const { return cmp(d)>0; }
70 bool operator>=(const DateTime &d) const { return cmp(d)>=0; }
72 int cmp(const DateTime &) const;
73 TimeStamp get_timestamp() const;
74 std::string format(const std::string &) const;
75 std::string format_rfc3339() const;
78 void add_raw(RawTime);
82 inline void operator<<(LexicalConverter &c, const DateTime &d)
83 { c.result(d.format_rfc3339()); }
85 inline void operator>>(const LexicalConverter &c, DateTime &d)
86 { d = DateTime::parse_rfc3339(c.get()); }