-/* $Id$ */
#ifndef MSP_TIME_DATETIME_H_
#define MSP_TIME_DATETIME_H_
-#include <stdint.h>
#include <string>
+#include "timezone.h"
+#include "rawtime.h"
namespace Msp {
namespace Time {
*/
class DateTime
{
+private:
+ 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 &);
- DateTime(int32_t, uint8_t, uint8_t);
- DateTime(int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
- DateTime(int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint32_t);
-
- int32_t get_year() const { return year; }
- uint8_t get_month() const { return month; }
- uint8_t get_mday() const { return mday; }
- uint8_t get_hour() const { return hour; }
- uint8_t get_minute() const { return minute; }
- uint8_t get_second() const { return second; }
- uint32_t get_usec() const { return usec; }
-
- void add_days(int32_t);
+ DateTime(const TimeStamp &, const TimeZone &);
+ 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);
+
+ 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; }
+
+ void add_days(int);
+ void set_timezone(const TimeZone &);
+ void convert_timezone(const TimeZone &);
DateTime operator+(const TimeDelta &) const;
DateTime &operator+=(const TimeDelta &);
+ DateTime operator-(const TimeDelta &) const;
+ DateTime &operator-=(const TimeDelta &);
bool operator==(const DateTime &d) const { return cmp(d)==0; }
bool operator!=(const DateTime &d) const { return cmp(d)!=0; }
int cmp(const DateTime &) const;
TimeStamp get_timestamp() const;
std::string format(const std::string &) const;
+ std::string format_rfc3339() const;
+
private:
- int32_t year;
- uint8_t month;
- uint8_t mday;
- uint8_t hour;
- uint8_t minute;
- uint8_t second;
- uint32_t usec;
-
- void add_raw(int64_t);
+ 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