]> git.tdb.fi Git - libs/core.git/blobdiff - source/time/datetime.h
Add move semantics to Variant
[libs/core.git] / source / time / datetime.h
index b786798707ab4db60c61b06263499ff7080f1b9b..2336374c6ae12164145f6afbb68bc26a23e22deb 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_TIME_DATETIME_H_
 
 #include <string>
+#include <msp/core/mspcore_api.h>
 #include "timezone.h"
 #include "rawtime.h"
 
@@ -20,17 +21,17 @@ Due to the complex internal representation, arithmetic operations on a DateTime
 are relatively slow.  For purposes of internal scheduling in a program, a
 TimeStamp is a better choice.
 */
-class DateTime
+class MSPCORE_API DateTime
 {
 private:
-       int           year;
-       unsigned char month;
-       unsigned char mday;
-       unsigned char hour;
-       unsigned char minute;
-       unsigned char second;
-       unsigned      usec;
-       TimeZone      zone;
+       int year = 1970;
+       unsigned char month = 1;
+       unsigned char mday = 1;
+       unsigned char hour = 0;
+       unsigned char minute = 0;
+       unsigned char second = 0;
+       unsigned usec = 0;
+       TimeZone zone;
 
 public:
        DateTime(const TimeStamp &);
@@ -38,18 +39,16 @@ public:
        DateTime(int, unsigned char, unsigned char);
        DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
        DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned);
-private:
-       void init(const TimeStamp &);
-       void init(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned);
 
-public:
-       int           get_year() const   { return year; }
-       unsigned char get_month() const  { return month; }
-       unsigned char get_mday() const   { return mday; }
-       unsigned char get_hour() const   { return hour; }
+       static DateTime parse_rfc3339(const std::string &);
+
+       int get_year() const { return year; }
+       unsigned char get_month() const { return month; }
+       unsigned char get_mday() const { return mday; }
+       unsigned char get_hour() const { return hour; }
        unsigned char get_minute() const { return minute; }
        unsigned char get_second() const { return second; }
-       unsigned      get_usec() const   { return usec; }
+       unsigned get_usec() const { return usec; }
 
        void add_days(int);
        void set_timezone(const TimeZone &);
@@ -77,6 +76,12 @@ private:
        void normalize();
 };
 
+inline void operator<<(LexicalConverter &c, const DateTime &d)
+{ c.result(d.format_rfc3339()); }
+
+inline void operator>>(const LexicalConverter &c, DateTime &d)
+{ d = DateTime::parse_rfc3339(c.get()); }
+
 } // namespace Time
 } // namespace Msp