00001
00049 #ifndef VLDTIMESTAMP_H
00050 #define VLDTIMESTAMP_H
00051
00052
00053
00054 #include "TTimeStamp.h"
00055
00056
00057 #include <iosfwd>
00058
00059 class VldTimeStamp;
00060 std::ostream& operator<<(std::ostream& os, const VldTimeStamp& vldts);
00061
00062 class VldTimeStamp {
00063
00064 friend Bool_t operator==(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00065 friend Bool_t operator!=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00066 friend Bool_t operator< (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00067 friend Bool_t operator<=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00068 friend Bool_t operator> (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00069 friend Bool_t operator>=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00070
00071 friend VldTimeStamp operator- (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00072
00073 public:
00074
00076 static VldTimeStamp GetBOT();
00077
00081 static VldTimeStamp GetEOT();
00082
00085 static VldTimeStamp GetNBOT();
00086
00088 VldTimeStamp();
00089
00091 VldTimeStamp(const VldTimeStamp &source)
00092 : fSec(source.fSec), fNanoSec(source.fNanoSec) { }
00093
00095 VldTimeStamp& operator=(const VldTimeStamp &source)
00096 { if (this != &source) {fSec = source.fSec; fNanoSec = source.fNanoSec;}
00097 return *this; }
00098
00100 VldTimeStamp(const timespec_t &ts)
00101 : fSec(ts.tv_sec), fNanoSec(ts.tv_nsec)
00102 { NormalizeNanoSec(); }
00103
00105 VldTimeStamp(const time_t &t, const Int_t nsec)
00106 : fSec(t), fNanoSec(nsec)
00107 { NormalizeNanoSec(); }
00108
00121 VldTimeStamp(UInt_t year, UInt_t month,
00122 UInt_t day, UInt_t hour,
00123 UInt_t min, UInt_t sec,
00124 UInt_t nsec=0,
00125 Bool_t isUTC=kTRUE, Int_t secOffset=0);
00126
00129 VldTimeStamp(UInt_t date, UInt_t time, UInt_t nsec,
00130 Bool_t isUTC=kTRUE, Int_t secOffset=0);
00131
00139 VldTimeStamp(Double_t seconds)
00140 : fSec((Int_t)seconds), fNanoSec((Int_t)((seconds-fSec)*1.0e9))
00141 { NormalizeNanoSec(); }
00142
00143
00144 virtual ~VldTimeStamp();
00145
00153 operator double() const { return fSec + 1.0e-9 * fNanoSec; }
00154
00155
00157 timespec_t GetTimeSpec() const
00158 { timespec_t value = {fSec,fNanoSec}; return value; }
00159
00161 time_t GetSec(void) const { return fSec;}
00163 Int_t GetNanoSec(void) const { return fNanoSec; }
00164
00166 Double_t GetSeconds(void) const { return fSec+(fNanoSec/1.0e9); }
00167
00200 const char *AsString(Option_t *option="") const;
00201 void Copy(VldTimeStamp &vldts) const;
00202
00205 Int_t GetDate(Bool_t inUTC=kTRUE, Int_t secOffset=0,
00206 UInt_t *year=0, UInt_t *month=0,
00207 UInt_t *day=0) const;
00208
00211 Int_t GetTime(Bool_t inUTC=kTRUE, Int_t secOffset=0,
00212 UInt_t* hour=0, UInt_t* min=0,
00213 UInt_t* sec=0) const;
00214
00215 void Add(const VldTimeStamp& offset);
00216 void Add(Double_t seconds);
00217
00218 void Print(Option_t *option="") const;
00219
00220
00221
00224 static Int_t GetZoneOffset();
00236 static time_t MktimeFromUTC(tm_t* tmstruct);
00238 static Bool_t IsLeapYear(Int_t year);
00240 static void DumpTMStruct(const tm_t& tmstruct);
00241
00242 private:
00243
00244 void Set();
00245 void Set(Int_t year, Int_t month, Int_t day,
00246 Int_t hour, Int_t min, Int_t sec,
00247 Int_t nsec, Bool_t isUTC, Int_t secOffset);
00248 void Set(Int_t date, Int_t time, Int_t nsec,
00249 Bool_t isUTC, Int_t secOffset);
00250 void NormalizeNanoSec();
00251
00252
00253
00254
00255
00256 Int_t fSec;
00257 Int_t fNanoSec;
00258
00259 ClassDef(VldTimeStamp,2)
00260 };
00261
00262 #ifndef __CINT__
00263
00264
00265
00266
00267 inline Bool_t operator==(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00268 { return lhs.fSec == rhs.fSec &&
00269 lhs.fNanoSec == rhs.fNanoSec; }
00270
00271 inline Bool_t operator!=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00272 { return lhs.fSec != rhs.fSec ||
00273 lhs.fNanoSec != rhs.fNanoSec; }
00274
00275 inline Bool_t operator<(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00276 { return lhs.fSec < rhs.fSec ||
00277 ( lhs.fSec == rhs.fSec &&
00278 lhs.fNanoSec < rhs.fNanoSec ); }
00279
00280 inline Bool_t operator<=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00281 { return lhs.fSec < rhs.fSec ||
00282 ( lhs.fSec == rhs.fSec &&
00283 lhs.fNanoSec <= rhs.fNanoSec ); }
00284
00285 inline Bool_t operator>(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00286 { return lhs.fSec > rhs.fSec ||
00287 ( lhs.fSec == rhs.fSec &&
00288 lhs.fNanoSec > rhs.fNanoSec ); }
00289
00290 inline Bool_t operator>=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00291 { return lhs.fSec > rhs.fSec ||
00292 ( lhs.fSec == rhs.fSec &&
00293 lhs.fNanoSec >= rhs.fNanoSec ); }
00294
00295 inline VldTimeStamp operator-(const VldTimeStamp& lhs, const VldTimeStamp& rhs)
00296 {
00297 return VldTimeStamp(lhs.GetSec() - rhs.GetSec(),
00298 lhs.GetNanoSec() - rhs.GetNanoSec());
00299 }
00300
00301 #endif
00302 #endif // VLDTIMESTAMP_H