62 if (os.tie()) os.tie()->flush();
66 if (os.flags() & std::ios::unitbuf) os.flush();
120 Set(year, month, day, hour, min, sec, nsec, isUTC, secOffset);
140 Set(date, time, nsec, isUTC, secOffset);
151 Set(tloc, isUTC, secOffset, dosDate);
170 Double_t D_r = D - fmod(2.0*D+1.0, 2.0)/2.0;
172 Double_t sidereal = (24110.54841 + 8640184.812866*T + 0.093142*T*T
173 - 0.0000062*T*T*T + (D - D_r)*86400.0*1.002737909350795)/3600.0;
174 Double_t rval = fmod(sidereal, 24.0);
175 return rval < 0 ? rval + 24.0 : rval;
199 return rval < 0 ? rval + 24.0 : rval;
215 return rval < 0 ? rval + 24.0 : rval;
231 return rval < 0 ? rval + 24.0 : rval;
271 const Int_t nbuffers = 8;
273 static Char_t formatted[nbuffers][64];
274 static Char_t formatted2[nbuffers][64];
276 static Int_t ibuffer = nbuffers;
280 ibuffer = (ibuffer+1)%nbuffers;
288 return formatted[ibuffer];
293 const Char_t *kRFC822 =
"%a, %d %b %Y %H:%M:%S %z (%Z) +#9ld nsec";
294 const Char_t *kISO8601 =
"%Y-%m-%d %H:%M:%S.#9.9ld%z";
295 const Char_t *kISO8601Z =
"%Y-%m-%d %H:%M:%S.#9.9ldZ";
298 const Char_t *kRFC822 =
"%a, %d %b %Y %H:%M:%S %Z +#9ld nsec";
299 const Char_t *kISO8601 =
"%Y-%m-%d %H:%M:%S.#9.9ld%Z";
300 const Char_t *kISO8601Z =
"%Y-%m-%d %H:%M:%S.#9.9ldZ";
302 const Char_t *kSQL =
"%Y-%m-%d %H:%M:%S";
306 if (asSQL) asLocal =
kFALSE;
311 if (!asLocal) format = kISO8601Z;
313 if (asSQL) format = kSQL;
316 time_t seconds = (time_t)
fSec;
319 struct tm *ptm = (asLocal) ? localtime_r(&seconds, &buf) : gmtime_r(&seconds, &buf);
321 struct tm *ptm = (asLocal) ? localtime(&seconds) : gmtime(&seconds);
326 strftime(formatted[ibuffer],
sizeof(formatted[ibuffer]), format, ptm);
328 if (asSQL)
return formatted[ibuffer];
331 Char_t *ptr = strrchr(formatted[ibuffer],
'#');
333 sprintf(formatted2[ibuffer], formatted[ibuffer],
fNanoSec);
335 return formatted2[ibuffer];
354 time_t atime =
fSec + secOffset;
357 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
359 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
362 if (day) *day = ptm->tm_mday;
363 if (month) *month = ptm->tm_mon + 1;
364 if (year) *year = ptm->tm_year + 1900;
366 return (1900+ptm->tm_year)*10000 + (1+ptm->tm_mon)*100 + ptm->tm_mday;
376 time_t atime =
fSec + secOffset;
379 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
381 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
384 if (hour) *hour = ptm->tm_hour;
385 if (min) *min = ptm->tm_min;
386 if (sec) *sec = ptm->tm_sec;
388 return ptm->tm_hour*10000 + ptm->tm_min*100 + ptm->tm_sec;
397 time_t atime =
fSec + secOffset;
400 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
402 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
405 Int_t day = ptm->tm_mday;
406 Int_t month = ptm->tm_mon + 1;
407 Int_t year = ptm->tm_year + 1900;
418 time_t atime =
fSec + secOffset;
421 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
423 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
426 Int_t day = ptm->tm_mday;
427 Int_t month = ptm->tm_mon + 1;
428 Int_t year = ptm->tm_year + 1900;
438 time_t atime =
fSec + secOffset;
441 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
443 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
446 return ptm->tm_mon + 1;
456 time_t atime =
fSec + secOffset;
459 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
461 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
464 Int_t day = ptm->tm_mday;
465 Int_t month = ptm->tm_mon + 1;
466 Int_t year = ptm->tm_year + 1900;
468 return GetWeek(day, month, year);
484 time_t atime =
fSec + secOffset;
487 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
489 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
492 Int_t year = ptm->tm_year + 1900;
507 #if defined(R__WINGCC)
510 #if !defined(R__FBSD) && !defined(R__OBSD)
517 return -localtime_r(&tp, &buf)->tm_gmtoff;
519 return -localtime(&tp)->tm_gmtoff;
558 GetSystemTimeAsFileTime((FILETIME *)&time);
563 (
unsigned __int64) 1000000000);
565 (
unsigned __int64) (1000*1000*10)
566 * (
unsigned __int64) (60 * 60 * 24)
567 * (
unsigned __int64) (134774);
569 fSec =
Int_t(time.QuadPart/(
unsigned __int64) (1000*1000*10));
572 gettimeofday(&tp, 0);
577 static Int_t sec = 0, nsec = 0, fake_ns = 0;
610 if (year <= 37) year += 2000;
611 if (year >= 70 && year <= 137) year += 1900;
613 if (year >= 1900) year -= 1900;
616 tmstruct.tm_year = year;
617 tmstruct.tm_mon = month-1;
618 tmstruct.tm_mday = day;
619 tmstruct.tm_hour = hour;
620 tmstruct.tm_min =
min;
621 tmstruct.tm_sec = sec + secOffset;
622 tmstruct.tm_isdst = -1;
624 const time_t bad_time_t = (time_t) -1;
629 time_t utc_sec = (isUTC) ?
MktimeFromUTC(&tmstruct) : mktime(&tmstruct);
631 if (utc_sec == bad_time_t)
632 Error(
"TTimeStamp::Set",
"mktime returned -1");
661 Int_t year = date/10000;
662 Int_t month = (date-year*10000)/100;
663 Int_t day = date%100;
666 const Int_t oneday = 240000;
671 while (time > oneday) {
675 Int_t hour = time/10000;
677 Int_t sec = time%100;
679 Set(year, month, day, hour, min, sec, nsec, isUTC, secOffset);
691 memset (&localtm, 0,
sizeof (localtm));
694 localtm.tm_year = ((tloc >> 25) & 0x7f) + 80;
695 localtm.tm_mon = ((tloc >> 21) & 0xf);
696 localtm.tm_mday = (tloc >> 16) & 0x1f;
697 localtm.tm_hour = (tloc >> 11) & 0x1f;
698 localtm.tm_min = (tloc >> 5) & 0x3f;
699 localtm.tm_sec = (tloc & 0x1f) * 2 + secOffset;
700 localtm.tm_isdst = -1;
702 time_t t = (time_t) tloc;
705 struct tm *tp = localtime_r(&t, &tpa);
707 struct tm *tp = localtime(&t);
709 localtm.tm_year = tp->tm_year;
710 localtm.tm_mon = tp->tm_mon;
711 localtm.tm_mday = tp->tm_mday;
712 localtm.tm_hour = tp->tm_hour;
713 localtm.tm_min = tp->tm_min;
714 localtm.tm_sec = tp->tm_sec + secOffset;
715 localtm.tm_isdst = -1;
718 const time_t bad_time_t = (time_t) -1;
723 time_t utc_sec = (isUTC && dosDate) ?
MktimeFromUTC(&localtm) : mktime(&localtm);
725 if (utc_sec == bad_time_t)
726 Error(
"TTimeStamp::Set",
"mktime returned -1");
739 const Int_t kNsPerSec = 1000000000;
767 Int_t daysInMonth[] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
768 Int_t year = tmstruct->tm_year + 1900;
773 Int_t &ref_tm_mon = tmstruct->tm_mon;
774 Int_t &ref_tm_mday = tmstruct->tm_mday;
776 tmstruct->tm_yday = 0;
777 for (
Int_t imonth = 0; imonth < ref_tm_mon; imonth++) {
778 tmstruct->tm_yday += daysInMonth[imonth];
780 tmstruct->tm_yday += ref_tm_mday - 1;
783 while (ref_tm_mday > daysInMonth[ref_tm_mon]) {
784 ref_tm_mday -= daysInMonth[ref_tm_mon];
791 tmstruct->tm_isdst = 0;
796 Int_t utc_sec = tmstruct->tm_sec +
797 tmstruct->tm_min*60 +
798 tmstruct->tm_hour*3600 +
799 tmstruct->tm_yday*86400 +
800 (tmstruct->tm_year-70)*31536000 +
801 ((tmstruct->tm_year-69)/4)*86400;
813 Int_t daysInMonth[] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
816 for (
Int_t i = 0; i < (month - 1); i++)
817 dayOfYear += daysInMonth[i];
836 dayno = 1 + day + 2*month + 3*(month + 1)/5 + year + year/4 - year/100 + year/400;
840 return ((dayno == 0) ? 7 : dayno);
852 Int_t week = (dayOfYear + dayJan1st - 2) / 7 + 1;
859 if (dayNextJan1st > 1 && dayNextJan1st < 5) {
863 }
else if (week == 0) {
865 week = (dayPrevJan1st < 5 && dayJan1st > 4) ? 53 : 52;
868 return year * 100 + week;
884 return (year % 4 == 0) && !((year % 100 == 0) && (year % 400 > 0));
903 printf(
" tm { year %4d, mon %2d, day %2d,\n",
907 printf(
" hour %2d, min %2d, sec %2d,\n",
911 printf(
" wday %2d, yday %3d, isdst %2d",
915 #if (defined(linux) && !defined(R__WINGCC)) || defined(R__MACOSX)
916 printf(
",\n tm_gmtoff %6ld, tm_zone \"%s\"",
917 #
if defined(__USE_BSD) || defined(R__MACOSX) || defined(__USE_MISC)
918 tmstruct.tm_gmtoff, tmstruct.tm_zone);
920 tmstruct.__tm_gmtoff, tmstruct.__tm_zone);
static time_t MktimeFromUTC(tm_t *tmstruct)
Equivalent of standard routine "mktime" but using the assumption that tm struct is filled with UTC...
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
const char * AsString(const Option_t *option="") const
Return the date & time as a string.
Double_t AsGAST(Double_t UT1Offset=0) const
Return Greenwich apparent sidereal time (GAST) in hour-angle.
RooArgList L(const RooAbsArg &v1)
Buffer base class used for serializing objects.
This class implements a mutex interface.
Double_t AsLMST(Double_t Longitude, Double_t UT1Offset=0) const
Return local mean sidereal time (LMST) in hour-angle, given a longitude in degrees.
void ToLower()
Change string to lower-case.
Double_t AsJulianDate() const
void NormalizeNanoSec()
Ensure that the fNanoSec field is in range [0,999999999].
static std::string format(double x, double y, int digits, int width)
void Add(const TTimeStamp &offset)
Add "offset" as a delta time.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
Int_t GetDayOfYear(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Get the day of the year represented by this time stamp value.
void Copy(TTimeStamp &ts) const
Copy this to ts.
void Set()
Set Date/Time to current time as reported by the system.
void Error(const char *location, const char *msgfmt,...)
TTimeStamp()
Default ctor.
void Print(const Option_t *option="") const
Print date and time.
static void DumpTMStruct(const tm_t &tmstruct)
Print out the "tm" structure: tmstruct.tm_year = year; // years since 1900 tmstruct.tm_mon = month-1; // months since Jan [0,11] tmstruct.tm_mday = day; // day of the month [1,31] tmstruct.tm_hour = hour; // hours since midnight [0,23] tmstruct.tm_min = min; // minutes after the hour [0,59] tmstruct.tm_sec = sec; // seconds after the minute [0,59] tmstruct.tm_wday // day of week [0,6] tmstruct.tm_yday // days in year [0,365] tmstruct.tm_isdst // DST [-1/0/1] (unknown,false,true).
Int_t GetWeek(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Get the week of the year.
UInt_t GetTime(Bool_t inUTC=kTRUE, Int_t secOffset=0, UInt_t *hour=0, UInt_t *min=0, UInt_t *sec=0) const
Return time in form of 123623 (i.e.
Double_t AsLAST(Double_t Longitude, Double_t UT1Offset=0) const
Return local apparent sidereal time (LAST) in hour-angle, given a longitude in degrees.
TBuffer & operator>>(TBuffer &buf, TTimeStamp &ts)
Read time stamp from TBuffer.
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
The TTimeStamp encapsulates seconds and ns since EPOCH.
Bool_t IsLeapYear(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Is the year a leap year.
Double_t AsGMST(Double_t UT1Offset=0) const
Return Greenwich mean sidereal time (GMST) in hour-angle.
std::ostream & operator<<(std::ostream &os, const TTimeStamp &ts)
Write time stamp to std::ostream.
UInt_t GetDate(Bool_t inUTC=kTRUE, Int_t secOffset=0, UInt_t *year=0, UInt_t *month=0, UInt_t *day=0) const
Return date in form of 19971224 (i.e.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Int_t GetDayOfWeek(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Method is using Zeller's formula for calculating the day number.
Int_t GetMonth(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Get the month of the year. Valid return values are between 1 and 12.
static Int_t GetZoneOffset()
Static method returning local (current) time zone offset from UTC.