X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ftime%2Fdatetime.h;h=a5d91cf3451d4b547e93698cabd1f191983b4b0f;hp=f065d3219e7f679d3741bf03dad4f2680d06a30d;hb=HEAD;hpb=1f0843257065789231a9949e0a81b79afd7bbebe diff --git a/source/time/datetime.h b/source/time/datetime.h index f065d32..2336374 100644 --- a/source/time/datetime.h +++ b/source/time/datetime.h @@ -2,6 +2,7 @@ #define MSP_TIME_DATETIME_H_ #include +#include #include "timezone.h" #include "rawtime.h" @@ -20,16 +21,16 @@ 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; + 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: @@ -38,11 +39,9 @@ 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: + 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; } @@ -80,6 +79,9 @@ private: 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