X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ftime%2Fdatetime.h;h=b7f578cd9f71326ae510c0780c8714f195aa684d;hp=7c2a349a869a794ff1876ec3029343d38dc48963;hb=be8ea216d23bf36bdfb2d3e302638782575fc136;hpb=b56eb5ec1da675da0c66abc53c1e4f6c4e4cccbd diff --git a/source/time/datetime.h b/source/time/datetime.h index 7c2a349..b7f578c 100644 --- a/source/time/datetime.h +++ b/source/time/datetime.h @@ -1,16 +1,9 @@ -/* $Id$ - -This file is part of libmspcore -Copyright © 2006 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_TIME_DATETIME_H_ #define MSP_TIME_DATETIME_H_ #include #include "timezone.h" -#include "types.h" +#include "rawtime.h" namespace Msp { namespace Time { @@ -30,14 +23,14 @@ TimeStamp is a better choice. class DateTime { private: - int year; + int year; unsigned char month; unsigned char mday; unsigned char hour; unsigned char minute; unsigned char second; - unsigned usec; - TimeZone zone; + unsigned usec; + TimeZone zone; public: DateTime(const TimeStamp &); @@ -50,13 +43,15 @@ private: 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 &); @@ -82,9 +77,14 @@ public: private: void add_raw(RawTime); void normalize(); - void validate() const; }; +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