00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef restcgi_date_time_h
00023 #define restcgi_date_time_h
00024 #include "apidefs.h"
00025 #include <time.h>
00026 #include <string>
00027 #include <iostream>
00028 namespace restcgi {
00030 class RESTCGI_API date_time {
00031 public:
00032 typedef struct ::tm tm_type;
00033
00034 date_time();
00037 date_time(const time_t& t);
00044 date_time(const tm_type& tm, bool check_wday = false);
00046 date_time(unsigned short y, unsigned char mon, unsigned char d, unsigned char h, unsigned char min, unsigned char s);
00056 date_time(const std::string& s);
00057 bool is_null() const {return time_ == NULL_TIME;}
00058 bool operator ==(const date_time& rhs) const {return time_ == rhs.time_;}
00059 bool operator !=(const date_time& rhs) const {return time_ != rhs.time_;}
00060 bool operator <(const date_time& rhs) const;
00061 operator time_t() const {return time_;}
00062
00063
00064 date_time operator +(int seconds) const {
00065 date_time result = *this;
00066 return result += seconds;
00067 }
00070 date_time& operator +=(int seconds);
00073 date_time operator -(int seconds) const {
00074 date_time result = *this;
00075 return result -= seconds;
00076 }
00079 date_time& operator -=(int seconds);
00082 tm_type tm() const;
00089 std::string string() const;
00095 std::string iso_string() const;
00096 static date_time now();
00097
00098
00099
00100
00101
00102 static void assert_in_range(const tm_type& v, bool check_wday);
00107 static time_t to_time(const tm_type& tm, bool check_wday);
00110 static tm_type to_tm(const time_t& t);
00113 static void to_tm(const time_t& t, tm_type& tm);
00114 static const time_t NULL_TIME;
00115 private:
00116 time_t time_;
00117 };
00123 bool RESTCGI_API parse(std::string::const_iterator& first, std::string::const_iterator last, date_time& v);
00124 }
00129 namespace uripp {
00130 std::string RESTCGI_API convert(const restcgi::date_time& v);
00131
00136 bool RESTCGI_API convert(const std::string& s, restcgi::date_time& v);
00137 }
00138 #endif