/home/greg/src/restcgi-test/src/date_time.h

00001 /*
00002 Copyright (c) 2009 zooml.com
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
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

Generated on Fri May 15 11:27:12 2009 for restcgi by  doxygen 1.4.7