3 This file is part of libmspcore
4 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_TIME_DATETIME_H_
9 #define MSP_TIME_DATETIME_H_
22 Provides handling of arbitary dates and times. Can represent a moment of time
23 in the range of about ±2.1×10⁹ years. It can also be formatted into a string
24 for presentation to the user.
26 Due to the complex internal representation, arithmetic operations on a DateTime
27 are relatively slow. For purposes of internal scheduling in a program, a
28 TimeStamp is a better choice.
43 DateTime(const TimeStamp &);
44 DateTime(const TimeStamp &, const TimeZone &);
45 DateTime(int, unsigned char, unsigned char);
46 DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
47 DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned);
49 void init(const TimeStamp &);
50 void init(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned);
53 int get_year() const { return year; }
54 unsigned char get_month() const { return month; }
55 unsigned char get_mday() const { return mday; }
56 unsigned char get_hour() const { return hour; }
57 unsigned char get_minute() const { return minute; }
58 unsigned char get_second() const { return second; }
59 unsigned get_usec() const { return usec; }
62 void set_timezone(const TimeZone &);
63 void convert_timezone(const TimeZone &);
65 DateTime operator+(const TimeDelta &) const;
66 DateTime &operator+=(const TimeDelta &);
67 DateTime operator-(const TimeDelta &) const;
68 DateTime &operator-=(const TimeDelta &);
70 bool operator==(const DateTime &d) const { return cmp(d)==0; }
71 bool operator!=(const DateTime &d) const { return cmp(d)!=0; }
72 bool operator<(const DateTime &d) const { return cmp(d)<0; }
73 bool operator<=(const DateTime &d) const { return cmp(d)<=0; }
74 bool operator>(const DateTime &d) const { return cmp(d)>0; }
75 bool operator>=(const DateTime &d) const { return cmp(d)>=0; }
77 int cmp(const DateTime &) const;
78 TimeStamp get_timestamp() const;
79 std::string format(const std::string &) const;
80 std::string format_rfc3339() const;
83 void add_raw(RawTime);
85 void validate() const;