00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
00014
00015
00016
00017
00018 #ifndef SIMPLE_TIME_H
00019 #define SIMPLE_TIME_H
00020
00021 #ifdef AIDA_STD
00022 # undef AIDA_STD
00023 #endif
00024
00025 #ifdef AIDA_DONT_USE_STD
00026 # define AIDA_STD
00027 #else
00028 # define AIDA_STD std
00029 #endif
00030
00031
00032 #include <time.h>
00033
00034
00035 #include <string>
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifdef _WIN32
00051 typedef __int64 TimeT;
00052 #else
00053
00054
00055
00056
00057 typedef long long TimeT;
00058 #endif
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00085 class timeAndDate_t {
00086 public:
00087 timeAndDate_t() :
00088 year(1970), month(1), day(1),
00089 hour(0), min(0), sec(0), ns(0),
00090 plusInf(false), minusInf(false)
00091 { }
00092
00093 public:
00094 unsigned short year;
00095 unsigned short month;
00096 unsigned short day;
00097 unsigned short hour;
00098 unsigned short min;
00099 unsigned short sec;
00100 unsigned long ns;
00101 bool plusInf;
00102 bool minusInf;
00103 };
00104
00105
00106
00107 class SimpleTimeDuration;
00108 class SimpleTimeInterval;
00109
00110
00111
00112
00125 class SimpleTime {
00126 public:
00127
00129
00130 SimpleTime(const SimpleTime & t) {timeval=t.toTimeT();};
00131 SimpleTime(const time_t & unix_time);
00132 SimpleTime(const TimeT & TimeT_time);
00133 SimpleTime(const timeAndDate_t & calendarTime);
00134 SimpleTime(const unsigned short year,
00135 const unsigned short month,
00136 const unsigned short day,
00137 const unsigned short hour,
00138 const unsigned short min,
00139 const unsigned short sec,
00140 const unsigned long ns=0,
00141 const bool plusInf=0,
00142 const bool minusInf=0);
00143 SimpleTime(const AIDA_STD::string & netLoggerString);
00144 ~SimpleTime() {};
00145
00146
00147 void operator = (const SimpleTime &);
00148 void operator = (const TimeT &);
00149 void operator += (const SimpleTimeDuration &);
00150 void operator -= (const SimpleTimeDuration &);
00151
00152 operator TimeT() const { return toTimeT(); }
00153
00154
00155 bool operator == (const SimpleTime &other) { return timeval == other.toTimeT(); }
00156 bool isBefore(const SimpleTime&) const;
00157
00160 TimeT time() const;
00161
00162
00163 void setPlusInf();
00164 void setMinusInf();
00165 bool isPlusInf() const;
00166 bool isMinusInf() const;
00167
00168
00169 TimeT toTimeT() const;
00170 time_t toUnixTime() const;
00171 void fromUnixTime(const time_t &unix_time);
00173 AIDA_STD::string toNetLogger() const;
00174 void fromNetLogger(const AIDA_STD::string &);
00175 void fromCalendarTime(const timeAndDate_t &);
00177 void fromCalendarTime(const unsigned short year,
00178 const unsigned short month,
00179 const unsigned short day,
00180 const unsigned short hour,
00181 const unsigned short minute,
00182 const unsigned short sec,
00183 const unsigned long nanosec=0,
00184 const bool plusInf=0,
00185 const bool minusInf=0);
00187 timeAndDate_t toCalendarTime() const;
00188 unsigned short year() const;
00189 unsigned short month() const;
00190 unsigned short day() const;
00191 unsigned short hour() const;
00192 unsigned short minute() const;
00193 unsigned short second() const;
00194 unsigned long nanosec() const;
00195
00196 private:
00197 TimeT timeval;
00198 };
00199
00200
00201 #ifndef _WIN32
00202 AIDA_STD::ostream & operator << (AIDA_STD::ostream & out, const SimpleTime &);
00203 #endif
00204 SimpleTime operator + (const SimpleTime &, const SimpleTimeDuration &);
00205 SimpleTime operator - (const SimpleTime &, const SimpleTimeDuration &);
00206
00207 #endif