63 if (os.tie()) os.tie()->flush();
67 if (os.flags() & std::ios::unitbuf) os.flush();
121 Set(year, month, day, hour, min, sec, nsec, isUTC, secOffset);
141 Set(date, time, nsec, isUTC, secOffset);
152 Set(tloc, isUTC, secOffset, dosDate);
171 Double_t D_r = D - fmod(2.0*D+1.0, 2.0)/2.0;
173 Double_t sidereal = (24110.54841 + 8640184.812866*T + 0.093142*T*T
174 - 0.0000062*T*T*T + (D - D_r)*86400.0*1.002737909350795)/3600.0;
175 Double_t rval = fmod(sidereal, 24.0);
176 return rval < 0 ? rval + 24.0 : rval;
193 Double_t Pi = 3.14159265358979323846;
195 Double_t epsilon = (23.4393 - 0.0000004 * D) * Pi / 180.0;
196 Double_t L = (280.47 + 0.98565 * D) * Pi / 180.0;
197 Double_t Omega = (125.04 - 0.052954 * D) * Pi / 180.0;
198 Double_t Deltapsi = -0.000319 * std::sin(Omega) - 0.000024 * std::sin(2.0 * L);
199 Double_t eqeq = Deltapsi * std::cos(epsilon);
201 return rval < 0 ? rval + 24.0 : rval;
217 return rval < 0 ? rval + 24.0 : rval;
233 return rval < 0 ? rval + 24.0 : rval;
273 const Int_t nbuffers = 8;
274 constexpr std::size_t bufferSize = 64;
276 static Char_t formatted[nbuffers][bufferSize];
277 static Char_t formatted2[nbuffers][bufferSize];
279 static Int_t ibuffer = nbuffers;
283 ibuffer = (ibuffer+1)%nbuffers;
291 return formatted[ibuffer];
296 const Char_t *kRFC822 =
"%a, %d %b %Y %H:%M:%S %z (%Z) +#9ld nsec";
297 const Char_t *kISO8601 =
"%Y-%m-%d %H:%M:%S.#9.9ld%z";
298 const Char_t *kISO8601Z =
"%Y-%m-%d %H:%M:%S.#9.9ldZ";
301 const Char_t *kRFC822 =
"%a, %d %b %Y %H:%M:%S %Z +#9ld nsec";
302 const Char_t *kISO8601 =
"%Y-%m-%d %H:%M:%S.#9.9ld%Z";
303 const Char_t *kISO8601Z =
"%Y-%m-%d %H:%M:%S.#9.9ldZ";
305 const Char_t *kSQL =
"%Y-%m-%d %H:%M:%S";
309 if (asSQL) asLocal =
kFALSE;
314 if (!asLocal)
format = kISO8601Z;
319 time_t seconds = (time_t)
fSec;
322 struct tm *ptm = (asLocal) ? localtime_r(&seconds, &buf) : gmtime_r(&seconds, &buf);
324 struct tm *ptm = (asLocal) ? localtime(&seconds) : gmtime(&seconds);
329 strftime(formatted[ibuffer],
sizeof(formatted[ibuffer]),
format, ptm);
331 if (asSQL)
return formatted[ibuffer];
334 Char_t *ptr = strrchr(formatted[ibuffer],
'#');
338 return formatted2[ibuffer];
357 time_t atime =
fSec + secOffset;
360 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
362 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
365 if (day) *day = ptm->tm_mday;
366 if (month) *month = ptm->tm_mon + 1;
367 if (year) *year = ptm->tm_year + 1900;
369 return (1900+ptm->tm_year)*10000 + (1+ptm->tm_mon)*100 + ptm->tm_mday;
379 time_t atime =
fSec + secOffset;
382 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
384 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
387 if (hour) *hour = ptm->tm_hour;
388 if (min) *min = ptm->tm_min;
389 if (sec) *sec = ptm->tm_sec;
391 return ptm->tm_hour*10000 + ptm->tm_min*100 + ptm->tm_sec;
400 time_t atime =
fSec + secOffset;
403 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
405 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
408 Int_t day = ptm->tm_mday;
409 Int_t month = ptm->tm_mon + 1;
410 Int_t year = ptm->tm_year + 1900;
421 time_t atime =
fSec + secOffset;
424 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
426 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
429 Int_t day = ptm->tm_mday;
430 Int_t month = ptm->tm_mon + 1;
431 Int_t year = ptm->tm_year + 1900;
441 time_t atime =
fSec + secOffset;
444 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
446 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
449 return ptm->tm_mon + 1;
459 time_t atime =
fSec + secOffset;
462 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
464 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
467 Int_t day = ptm->tm_mday;
468 Int_t month = ptm->tm_mon + 1;
469 Int_t year = ptm->tm_year + 1900;
471 return GetWeek(day, month, year);
487 time_t atime =
fSec + secOffset;
490 struct tm *ptm = (inUTC) ? gmtime_r(&atime, &buf) : localtime_r(&atime, &buf);
492 struct tm *ptm = (inUTC) ? gmtime(&atime) : localtime(&atime);
495 Int_t year = ptm->tm_year + 1900;
510#if defined(R__WINGCC)
513#if !defined(R__FBSD) && !defined(R__OBSD)
520 return -localtime_r(&tp, &buf)->tm_gmtoff;
522 return -localtime(&tp)->tm_gmtoff;
561 GetSystemTimeAsFileTime((FILETIME *)&time);
566 (
unsigned __int64) 1000000000);
568 (
unsigned __int64) (1000*1000*10)
569 * (
unsigned __int64) (60 * 60 * 24)
570 * (
unsigned __int64) (134774);
572 fSec =
Int_t(time.QuadPart/(
unsigned __int64) (1000*1000*10));
575 gettimeofday(&tp,
nullptr);
580 static Int_t sec = 0, nsec = 0, fake_ns = 0;
613 if (year <= 37) year += 2000;
614 if (year >= 70 && year <= 137) year += 1900;
616 if (year >= 1900) year -= 1900;
619 tmstruct.tm_year = year;
620 tmstruct.tm_mon = month-1;
621 tmstruct.tm_mday = day;
622 tmstruct.tm_hour = hour;
623 tmstruct.tm_min = min;
624 tmstruct.tm_sec = sec + secOffset;
625 tmstruct.tm_isdst = -1;
627 const time_t bad_time_t = (time_t) -1;
632 time_t utc_sec = (isUTC) ?
MktimeFromUTC(&tmstruct) : mktime(&tmstruct);
634 if (utc_sec == bad_time_t)
635 Error(
"TTimeStamp::Set",
"mktime returned -1");
664 Int_t year = date/10000;
665 Int_t month = (date-year*10000)/100;
666 Int_t day = date%100;
669 const Int_t oneday = 240000;
674 while (time > oneday) {
678 Int_t hour = time/10000;
679 Int_t min = (time-hour*10000)/100;
680 Int_t sec = time%100;
682 Set(year, month, day, hour, min, sec, nsec, isUTC, secOffset);
694 memset (&localtm, 0,
sizeof (localtm));
697 localtm.tm_year = ((tloc >> 25) & 0x7f) + 80;
698 localtm.tm_mon = ((tloc >> 21) & 0xf);
699 localtm.tm_mday = (tloc >> 16) & 0x1f;
700 localtm.tm_hour = (tloc >> 11) & 0x1f;
701 localtm.tm_min = (tloc >> 5) & 0x3f;
702 localtm.tm_sec = (tloc & 0x1f) * 2 + secOffset;
703 localtm.tm_isdst = -1;
705 time_t t = (time_t) tloc;
708 struct tm *tp = localtime_r(&t, &tpa);
710 struct tm *tp = localtime(&t);
712 localtm.tm_year = tp->tm_year;
713 localtm.tm_mon = tp->tm_mon;
714 localtm.tm_mday = tp->tm_mday;
715 localtm.tm_hour = tp->tm_hour;
716 localtm.tm_min = tp->tm_min;
717 localtm.tm_sec = tp->tm_sec + secOffset;
718 localtm.tm_isdst = -1;
721 const time_t bad_time_t = (time_t) -1;
726 time_t utc_sec = (isUTC && dosDate) ?
MktimeFromUTC(&localtm) : mktime(&localtm);
728 if (utc_sec == bad_time_t)
729 Error(
"TTimeStamp::Set",
"mktime returned -1");
742 const Int_t kNsPerSec = 1000000000;
770 Int_t daysInMonth[] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
771 Int_t year = tmstruct->tm_year + 1900;
776 Int_t &ref_tm_mon = tmstruct->tm_mon;
777 Int_t &ref_tm_mday = tmstruct->tm_mday;
779 tmstruct->tm_yday = 0;
780 for (
Int_t imonth = 0; imonth < ref_tm_mon; imonth++) {
781 tmstruct->tm_yday += daysInMonth[imonth];
783 tmstruct->tm_yday += ref_tm_mday - 1;
786 while (ref_tm_mday > daysInMonth[ref_tm_mon]) {
787 ref_tm_mday -= daysInMonth[ref_tm_mon];
794 tmstruct->tm_isdst = 0;
799 Int_t utc_sec = tmstruct->tm_sec +
800 tmstruct->tm_min*60 +
801 tmstruct->tm_hour*3600 +
802 tmstruct->tm_yday*86400 +
803 (tmstruct->tm_year-70)*31536000 +
804 ((tmstruct->tm_year-69)/4)*86400;
816 Int_t daysInMonth[] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
819 for (
Int_t i = 0; i < (month - 1); i++)
820 dayOfYear += daysInMonth[i];
839 dayno = 1 + day + 2*month + 3*(month + 1)/5 + year + year/4 - year/100 + year/400;
843 return ((dayno == 0) ? 7 : dayno);
855 Int_t week = (dayOfYear + dayJan1st - 2) / 7 + 1;
862 if (dayNextJan1st > 1 && dayNextJan1st < 5) {
866 }
else if (week == 0) {
868 week = (dayPrevJan1st < 5 && dayJan1st > 4) ? 53 : 52;
871 return year * 100 + week;
887 return (year % 4 == 0) && !((year % 100 == 0) && (year % 400 > 0));
906 printf(
" tm { year %4d, mon %2d, day %2d,\n",
910 printf(
" hour %2d, min %2d, sec %2d,\n",
914 printf(
" wday %2d, yday %3d, isdst %2d",
918#if (defined(linux) && !defined(R__WINGCC)) || defined(R__MACOSX)
919 printf(
",\n tm_gmtoff %6ld, tm_zone \"%s\"",
920#
if defined(__USE_BSD) || defined(R__MACOSX) || defined(__USE_MISC)
921 tmstruct.tm_gmtoff, tmstruct.tm_zone);
923 tmstruct.__tm_gmtoff, tmstruct.__tm_zone);
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
TBuffer & operator>>(TBuffer &buf, TTimeStamp &ts)
Read time stamp from TBuffer.
TVirtualMutex * gTimeMutex
R__EXTERN TVirtualMutex * gTimeMutex
#define R__LOCKGUARD2(mutex)
Buffer base class used for serializing objects.
void Streamer(TBuffer &) override
Stream an object of class TObject.
void ToLower()
Change string to lower-case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
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.
UInt_t GetTime(Bool_t inUTC=kTRUE, Int_t secOffset=0, UInt_t *hour=nullptr, UInt_t *min=nullptr, UInt_t *sec=nullptr) 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.
Int_t GetDayOfYear(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Get the day of the year represented by this time stamp value.
static void DumpTMStruct(const tm_t &tmstruct)
Print out the "tm" structure:
Int_t GetWeek(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Get the week of the year.
TTimeStamp()
Default ctor.
Double_t AsJulianDate() const
void Add(const TTimeStamp &offset)
Add "offset" as a delta time.
void Copy(TTimeStamp &ts) const
Copy this to ts.
virtual void Streamer(TBuffer &)
Int_t GetDayOfWeek(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Method is using Zeller's formula for calculating the day number.
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.
Double_t AsGMST(Double_t UT1Offset=0) const
Return Greenwich mean sidereal time (GMST) in hour-angle.
void Print(const Option_t *option="") const
Print date and time.
void Set()
Set Date/Time to current time as reported by the system.
Double_t AsGAST(Double_t UT1Offset=0) const
Return Greenwich apparent sidereal time (GAST) in hour-angle.
static Int_t GetZoneOffset()
Static method returning local (current) time zone offset from UTC.
static time_t MktimeFromUTC(tm_t *tmstruct)
Equivalent of standard routine "mktime" but using the assumption that tm struct is filled with UTC,...
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.
const char * AsString(const Option_t *option="") const
Return the date & time as a string.
UInt_t GetDate(Bool_t inUTC=kTRUE, Int_t secOffset=0, UInt_t *year=nullptr, UInt_t *month=nullptr, UInt_t *day=nullptr) const
Return date in form of 19971224 (i.e.
void NormalizeNanoSec()
Ensure that the fNanoSec field is in range [0,999999999].
This class implements a mutex interface.