12 #ifndef ROOT_TTimeStamp
13 #define ROOT_TTimeStamp
46 #if defined (_MSC_VER) && (_MSC_VER < 1900)
54 typedef struct timespec timespec_t;
55 typedef struct tm tm_t;
59 std::ostream &operator<<(std::ostream &os,
const TTimeStamp &ts);
60 TBuffer &operator<<(TBuffer &buf,
const TTimeStamp &ts);
61 TBuffer &operator>>(TBuffer &buf, TTimeStamp &ts);
62 Bool_t operator==(
const TTimeStamp &lhs,
const TTimeStamp &rhs);
63 Bool_t operator!=(
const TTimeStamp &lhs,
const TTimeStamp &rhs);
64 Bool_t operator< (
const TTimeStamp &lhs,
const TTimeStamp &rhs);
65 Bool_t operator<=(
const TTimeStamp &lhs,
const TTimeStamp &rhs);
66 Bool_t operator> (
const TTimeStamp &lhs,
const TTimeStamp &rhs);
67 Bool_t operator>=(
const TTimeStamp &lhs,
const TTimeStamp &rhs);
69 R__EXTERN TVirtualMutex *gTimeMutex;
73 friend Bool_t operator==(
const TTimeStamp &lhs,
const TTimeStamp &rhs);
74 friend Bool_t operator!=(
const TTimeStamp &lhs,
const TTimeStamp &rhs);
75 friend Bool_t operator< (
const TTimeStamp &lhs,
const TTimeStamp &rhs);
76 friend Bool_t operator<=(
const TTimeStamp &lhs,
const TTimeStamp &rhs);
77 friend Bool_t operator> (
const TTimeStamp &lhs,
const TTimeStamp &rhs);
78 friend Bool_t operator>=(
const TTimeStamp &lhs,
const TTimeStamp &rhs);
84 void NormalizeNanoSec();
91 TTimeStamp(
const timespec_t &ts) :
92 fSec(Int_t(ts.tv_sec)), fNanoSec(ts.tv_nsec) { NormalizeNanoSec(); }
95 TTimeStamp(time_t t, Int_t nsec) :
96 fSec(Int_t(t)), fNanoSec(nsec) { NormalizeNanoSec(); }
99 TTimeStamp(UInt_t year, UInt_t month,
100 UInt_t day, UInt_t hour,
101 UInt_t min, UInt_t sec,
102 UInt_t nsec = 0, Bool_t isUTC = kTRUE, Int_t secOffset = 0);
105 TTimeStamp(UInt_t date, UInt_t time, UInt_t nsec,
106 Bool_t isUTC = kTRUE, Int_t secOffset = 0);
109 TTimeStamp(UInt_t tloc, Bool_t isUTC = kTRUE, Int_t secOffset = 0,
110 Bool_t dosDate = kFALSE);
112 virtual ~TTimeStamp() { }
118 void Set(Int_t year, Int_t month, Int_t day,
119 Int_t hour, Int_t min, Int_t sec,
120 Int_t nsec, Bool_t isUTC, Int_t secOffset);
123 void Set(Int_t date, Int_t time, Int_t nsec,
124 Bool_t isUTC, Int_t secOffset);
127 void Set(UInt_t tloc, Bool_t isUTC, Int_t secOffset, Bool_t dosDate);
130 void SetSec(Int_t sec) { fSec = sec; }
131 void SetNanoSec(Int_t nsec) { fNanoSec = nsec; }
133 timespec_t GetTimeSpec()
const
134 { timespec_t value = {fSec,fNanoSec};
return value; }
135 time_t GetSec()
const {
return fSec; }
136 Int_t GetNanoSec()
const {
return fNanoSec; }
138 Double_t AsDouble()
const {
return fSec + 1e-9 * fNanoSec; }
139 Double_t AsJulianDate()
const {
return (AsDouble()/86400.0 + 2440587.5); }
142 Double_t AsGMST(Double_t UT1Offset = 0 )
const;
143 Double_t AsGAST(Double_t UT1Offset = 0 )
const;
144 Double_t AsLMST(Double_t Longitude , Double_t UT1Offset = 0 )
const;
145 Double_t AsLAST(Double_t Longitude , Double_t UT1Offset = 0 )
const;
147 const char *AsString(
const Option_t *option=
"")
const;
149 void Copy(TTimeStamp &ts)
const;
150 UInt_t GetDate(Bool_t inUTC = kTRUE, Int_t secOffset = 0,
151 UInt_t *year = 0, UInt_t *month = 0,
152 UInt_t *day = 0)
const;
153 UInt_t GetTime(Bool_t inUTC = kTRUE, Int_t secOffset = 0,
154 UInt_t *hour = 0, UInt_t *min = 0,
155 UInt_t *sec = 0)
const;
156 Int_t GetDayOfYear(Bool_t inUTC = kTRUE, Int_t secOffset = 0)
const;
157 Int_t GetDayOfWeek(Bool_t inUTC = kTRUE, Int_t secOffset = 0)
const;
158 Int_t GetMonth(Bool_t inUTC = kTRUE, Int_t secOffset = 0)
const;
159 Int_t GetWeek(Bool_t inUTC = kTRUE, Int_t secOffset = 0)
const;
160 Bool_t IsLeapYear(Bool_t inUTC = kTRUE, Int_t secOffset = 0)
const;
162 void Add(
const TTimeStamp &offset);
164 void Print(
const Option_t *option=
"")
const;
166 operator double()
const {
return AsDouble(); }
169 static Int_t GetZoneOffset();
170 static time_t MktimeFromUTC(tm_t *tmstruct);
171 static void DumpTMStruct(
const tm_t &tmstruct);
172 static Int_t GetDayOfYear(Int_t day, Int_t month, Int_t year);
173 static Int_t GetDayOfWeek(Int_t day, Int_t month, Int_t year);
174 static Int_t GetWeek(Int_t day, Int_t month, Int_t year);
175 static Bool_t IsLeapYear(Int_t year);
177 ClassDef(TTimeStamp,1)
181 inline Bool_t operator==(
const TTimeStamp &lhs,
const TTimeStamp &rhs)
182 {
return lhs.fSec == rhs.fSec &&
183 lhs.fNanoSec == rhs.fNanoSec; }
185 inline Bool_t operator!=(
const TTimeStamp &lhs,
const TTimeStamp &rhs)
186 {
return lhs.fSec != rhs.fSec ||
187 lhs.fNanoSec != rhs.fNanoSec; }
189 inline Bool_t operator<(
const TTimeStamp &lhs,
const TTimeStamp &rhs)
190 {
return lhs.fSec < rhs.fSec ||
191 (lhs.fSec == rhs.fSec &&
192 lhs.fNanoSec < rhs.fNanoSec); }
194 inline Bool_t operator<=(
const TTimeStamp &lhs,
const TTimeStamp &rhs)
195 {
return lhs.fSec < rhs.fSec ||
196 (lhs.fSec == rhs.fSec &&
197 lhs.fNanoSec <= rhs.fNanoSec); }
199 inline Bool_t operator>(
const TTimeStamp &lhs,
const TTimeStamp &rhs)
200 {
return lhs.fSec > rhs.fSec ||
201 (lhs.fSec == rhs.fSec &&
202 lhs.fNanoSec > rhs.fNanoSec); }
204 inline Bool_t operator>=(
const TTimeStamp &lhs,
const TTimeStamp &rhs)
205 {
return lhs.fSec > rhs.fSec ||
206 (lhs.fSec == rhs.fSec &&
207 lhs.fNanoSec >= rhs.fNanoSec); }