00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifndef VLDTIMESTAMP_H
00050 #define VLDTIMESTAMP_H
00051
00052
00053
00054 #include "TTimeStamp.h"
00055
00056
00057 #include <iosfwd>
00058
00059
00060 class TVldTimeStamp;
00061
00062 class TVldTimeStamp {
00063
00064 friend Bool_t operator==(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs);
00065 friend Bool_t operator!=(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs);
00066 friend Bool_t operator< (const TVldTimeStamp &lhs, const TVldTimeStamp &rhs);
00067 friend Bool_t operator<=(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs);
00068 friend Bool_t operator> (const TVldTimeStamp &lhs, const TVldTimeStamp &rhs);
00069 friend Bool_t operator>=(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs);
00070
00071 friend TVldTimeStamp operator- (const TVldTimeStamp &lhs, const TVldTimeStamp &rhs);
00072
00073 public:
00074
00075
00076 static TVldTimeStamp GetBOT();
00077
00078
00079
00080
00081 static TVldTimeStamp GetEOT();
00082
00083
00084
00085 static TVldTimeStamp GetNBOT();
00086
00087
00088 TVldTimeStamp();
00089
00090
00091 TVldTimeStamp(const TVldTimeStamp &source)
00092 : fSec(source.fSec),
00093 fNanoSec(source.fNanoSec) { }
00094
00095
00096 TVldTimeStamp& operator=(const TVldTimeStamp &source)
00097 { if (this != &source) {fSec = source.fSec; fNanoSec = source.fNanoSec;}
00098 return *this; }
00099
00100
00101 TVldTimeStamp(const timespec_t &ts)
00102 : fSec(ts.tv_sec), fNanoSec(ts.tv_nsec)
00103 { NormalizeNanoSec(); }
00104
00105
00106 TVldTimeStamp(const time_t &t, const Int_t nsec)
00107 : fSec(t), fNanoSec(nsec)
00108 { NormalizeNanoSec(); }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 TVldTimeStamp(UInt_t year, UInt_t month,
00123 UInt_t day, UInt_t hour,
00124 UInt_t min, UInt_t sec,
00125 UInt_t nsec=0,
00126 Bool_t isUTC=kTRUE, Int_t secOffset=0);
00127
00128
00129
00130 TVldTimeStamp(UInt_t date, UInt_t time, UInt_t nsec,
00131 Bool_t isUTC=kTRUE, Int_t secOffset=0);
00132
00133
00134
00135
00136
00137
00138
00139
00140 TVldTimeStamp(Double_t seconds)
00141 : fSec((Int_t)seconds), fNanoSec((Int_t)((seconds-fSec)*1.0e9))
00142 { NormalizeNanoSec(); }
00143
00144
00145 virtual ~TVldTimeStamp();
00146
00147
00148
00149
00150
00151
00152
00153
00154 operator double() const { return fSec + 1.0e-9 * fNanoSec; }
00155
00156
00157
00158 timespec_t GetTimeSpec() const
00159 { timespec_t value = {fSec,fNanoSec}; return value; }
00160
00161
00162 time_t GetSec(void) const { return fSec;}
00163
00164 Int_t GetNanoSec(void) const { return fNanoSec; }
00165
00166
00167 Double_t GetSeconds(void) const { return fSec+(fNanoSec/1.0e9); }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 const char *AsString(Option_t *option="") const;
00202 void Copy(TVldTimeStamp &vldts) const;
00203
00204
00205
00206 Int_t GetDate(Bool_t inUTC=kTRUE, Int_t secOffset=0,
00207 UInt_t *year=0, UInt_t *month=0,
00208 UInt_t *day=0) const;
00209
00210
00211
00212 Int_t GetTime(Bool_t inUTC=kTRUE, Int_t secOffset=0,
00213 UInt_t* hour=0, UInt_t* min=0,
00214 UInt_t* sec=0) const;
00215
00216 void Add(const TVldTimeStamp& offset);
00217 void Add(Double_t seconds);
00218
00219 void Print(Option_t *option="") const;
00220
00221
00222
00223
00224
00225 static Int_t GetZoneOffset();
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 static time_t MktimeFromUTC(tm_t* tmstruct);
00238
00239 static Bool_t IsLeapYear(Int_t year);
00240
00241 static void DumpTMStruct(const tm_t& tmstruct);
00242
00243 private:
00244
00245 void Set();
00246 void Set(Int_t year, Int_t month, Int_t day,
00247 Int_t hour, Int_t min, Int_t sec,
00248 Int_t nsec, Bool_t isUTC, Int_t secOffset);
00249 void Set(Int_t date, Int_t time, Int_t nsec,
00250 Bool_t isUTC, Int_t secOffset);
00251 void NormalizeNanoSec();
00252
00253
00254
00255
00256
00257 Int_t fSec;
00258 Int_t fNanoSec;
00259
00260 ClassDef(TVldTimeStamp,2)
00261 };
00262 std::ostream& operator<<(std::ostream& os, const TVldTimeStamp& vldts);
00263
00264 #ifndef __CINT__
00265
00266
00267
00268
00269
00270
00271 inline Bool_t operator==(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs)
00272 { return lhs.fSec == rhs.fSec &&
00273 lhs.fNanoSec == rhs.fNanoSec; }
00274
00275 inline Bool_t operator!=(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs)
00276 { return lhs.fSec != rhs.fSec ||
00277 lhs.fNanoSec != rhs.fNanoSec; }
00278
00279 inline Bool_t operator<(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs)
00280 { return lhs.fSec < rhs.fSec ||
00281 ( lhs.fSec == rhs.fSec &&
00282 lhs.fNanoSec < rhs.fNanoSec ); }
00283
00284 inline Bool_t operator<=(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs)
00285 { return lhs.fSec < rhs.fSec ||
00286 ( lhs.fSec == rhs.fSec &&
00287 lhs.fNanoSec <= rhs.fNanoSec ); }
00288
00289 inline Bool_t operator>(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs)
00290 { return lhs.fSec > rhs.fSec ||
00291 ( lhs.fSec == rhs.fSec &&
00292 lhs.fNanoSec > rhs.fNanoSec ); }
00293
00294 inline Bool_t operator>=(const TVldTimeStamp &lhs, const TVldTimeStamp &rhs)
00295 { return lhs.fSec > rhs.fSec ||
00296 ( lhs.fSec == rhs.fSec &&
00297 lhs.fNanoSec >= rhs.fNanoSec ); }
00298
00299 inline TVldTimeStamp operator-(const TVldTimeStamp& lhs, const TVldTimeStamp& rhs)
00300 {
00301 return TVldTimeStamp(lhs.GetSec() - rhs.GetSec(),
00302 lhs.GetNanoSec() - rhs.GetNanoSec());
00303 }
00304
00305
00306 #endif
00307 #endif // VLDTIMESTAMP_H