00001
00002 #ifndef FACILITIES_TIMESTAMP_H
00003 #define FACILITIES_TIMESTAMP_H
00004
00005 #include <string>
00006
00007 namespace facilities {
00008
00013 class BadTimeInput {
00014 public:
00015 BadTimeInput(std::string msg) : complaint(msg) {};
00016 ~BadTimeInput() {};
00017 std::string complaint;
00018
00019 BadTimeInput(const BadTimeInput &other) {complaint = other.complaint; };
00020 };
00021
00022
00049 class Timestamp {
00050 public:
00053 Timestamp();
00054
00058 Timestamp(long int seconds, int nano = 0, int tzOffset = 0);
00059
00061 Timestamp(double julian);
00062
00063
00074 Timestamp(const std::string& str, int tzOffset = 0);
00075
00077 Timestamp(int year, int month, int day,
00078 int hour = 0, int minute = 0,
00079 int second = 0, int nano = 0);
00080
00082 std::string getString() const;
00083
00085 double getJulian() const;
00086
00087 double getNano() const {return m_nano;}
00088 long int getClibTime() const {return m_time;}
00089
00090 bool operator<(const Timestamp& other) const {
00091 return ((m_time < other.m_time) ||
00092 ((m_time == other.m_time) && (m_nano < other.m_nano)));
00093 }
00094
00095 bool operator>(const Timestamp& other) const {
00096 return (other < (*this));
00097
00098 }
00099
00100 bool operator<=(const Timestamp& other) const {
00101 return ( !(other < (*this)) );
00102 }
00103
00104 bool operator>=(const Timestamp& other) const {
00105 return ( !( (*this) < other ) );
00106 }
00107
00108
00109 Timestamp& operator= (const Timestamp& other) {
00110 m_time = other.m_time; m_nano = other.m_nano;
00111 return *this;
00112 }
00113
00114 bool operator==(const Timestamp& other) const{
00115 return ((m_time == other.m_time) && (m_nano == other.m_nano));
00116 }
00117
00118 bool operator!=(const Timestamp& other) const {
00119 return (!(*this == other));
00120 }
00121
00122
00123 private:
00124
00125
00126
00127 static const double julian1970;
00128 static const int secPerDay;
00129 static const double inverseNano;
00130 static const int inverseNanoInt;
00131 static const long int maxInt;
00132
00137 class TZOffset {
00138 public:
00139 TZOffset();
00140 long int m_tzseconds;
00141 int m_isDst;
00142 };
00143 static TZOffset s_tz;
00144
00146 static time_t toBinary(const std::string& strTime);
00147
00149 static void toString(time_t bin, std::string& strTime);
00150
00151 protected:
00153 time_t m_time;
00154
00156 int m_nano;
00157 };
00158
00159 }
00160
00161 #endif