68 Set(year, month, day, hour, min, sec);
85 static TString weekDays[7] = {
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun" };
88 for (day = 0; day < 7; day++) {
89 if (wd(0, 3) == weekDays[day])
92 return (day < 7) ? day+1: -1;
102 char *retStr = ctime(&t);
107 static const char *defaulttime =
"15/06/96";
108 Error(
"TDatime::AsString",
"could not get time string");
122 #if defined(R__SOLARIS) && (_POSIX_C_SOURCE - 0 < 199506L)
123 char *retStr = ctime_r(&t, out, 26);
125 char *retStr = ctime_r(&t, out);
128 char *retStr = ctime(&t);
137 static const char *defaulttime =
"15/06/96";
138 strcpy(out, defaulttime);
139 Error(
"TDatime::AsString",
"could not get time string");
151 static char sqldate[20];
154 UInt_t month = (fDatime<<6)>>28;
155 UInt_t day = (fDatime<<10)>>27;
156 UInt_t hour = (fDatime<<15)>>27;
158 UInt_t sec = (fDatime<<26)>>26;
160 snprintf(sqldate,20,
"%04d-%02d-%02d %02d:%02d:%02d", (year+1995), month, day,
182 UInt_t month = (fDatime<<6)>>28;
183 UInt_t day = (fDatime<<10)>>27;
184 UInt_t hour = (fDatime<<15)>>27;
186 UInt_t sec = (fDatime<<26)>>26;
189 tp.tm_year = year+95;
197 time_t t = mktime(&tp);
199 Error(
"TDatime::Convert",
"error converting fDatime to time_t");
205 struct tm *tgp = gmtime_r(&t, &tg);
207 struct tm *tgp = gmtime(&t);
248 UInt_t month = (fDatime<<6)>>28;
249 UInt_t day = (fDatime<<10)>>27;
250 return 10000*(year+1995) + 100*month + day;
258 UInt_t hour = (fDatime<<15)>>27;
260 UInt_t sec = (fDatime<<26)>>26;
261 return 10000*hour + 100*min + sec;
289 time_t tloc = time(0);
292 struct tm *tp = localtime_r(&tloc, &tpa);
294 struct tm *tp = localtime(&tloc);
296 UInt_t year = tp->tm_year;
297 UInt_t month = tp->tm_mon + 1;
299 UInt_t hour = tp->tm_hour;
305 UInt_t year = tp.wYear-1900;
313 fDatime = (year-95)<<26 | month<<22 | day<<17 | hour<<12 | min<<6 | sec;
327 year = ((tloc >> 25) & 0x7f) + 80;
328 month = ((tloc >> 21) & 0xf);
329 day = (tloc >> 16) & 0x1f;
330 hour = (tloc >> 11) & 0x1f;
331 min = (tloc >> 5) & 0x3f;
332 sec = (tloc & 0x1f) * 2;
334 time_t t = (time_t) tloc;
337 struct tm *tp = localtime_r(&t, &tpa);
339 struct tm *tp = localtime(&t);
342 month = tp->tm_mon + 1;
349 fDatime = (year-95)<<26 | month<<22 | day<<17 | hour<<12 | min<<6 | sec;
362 if (date > 19000000) date -= 19000000;
364 Error(
"TDatime::Set",
"year smaller than 1995");
368 Int_t year = date/10000;
369 Int_t month = (date-year*10000)/100;
370 Int_t day = date%100;
375 min = (time-hour*10000)/100;
378 fDatime = (year-95)<<26 | month<<22 | day<<17 | hour<<12 | min<<6 | sec;
388 if (year < 159) year += 1900;
390 Error(
"TDatime::Set",
"year must be >= 1995");
394 fDatime = (year-1995)<<26 | month<<22 | day<<17 | hour<<12 | min<<6 | sec;
403 Int_t yy, mm, dd, hh, mi, ss;
405 if (sscanf(sqlDateTime,
"%d-%d-%d %d:%d:%d", &yy, &mm, &dd, &hh, &mi, &ss) == 6)
406 Set(yy, mm, dd, hh, mi, ss);
408 Error(
"TDatime(sqlDatTime)",
"input string not in right format, set"
409 " to current date/time");
417 void TDatime::Streamer(
TBuffer &b)
434 UInt_t year = datetime>>26;
435 UInt_t month = (datetime<<6)>>28;
436 UInt_t day = (datetime<<10)>>27;
437 UInt_t hour = (datetime<<15)>>27;
439 UInt_t sec = (datetime<<26)>>26;
440 date = 10000*(year+1995) + 100*month + day;
441 time = 10000*hour + 100*min + sec;
449 return std::string(val.
AsString(buf));
void frombuf(char *&buf, Bool_t *x)
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
void Set()
Set Date/Time to current time as reported by the system.
void Copy(TDatime &datime) const
Copy this to datime.
UInt_t Get() const
Return raw date/time as encoded by TDatime.
Buffer base class used for serializing objects.
void ReadBuffer(char *&buffer)
Decode Date/Time from output buffer, used by I/O system.
ClassImp(TDatime) TDatime
Create a TDatime and set it to the current time.
Int_t GetTime() const
Return time in form of 123623 (i.e. 12:36:23)
Int_t GetDayOfWeek() const
Returns day of week, with Monday being day 1 and Sunday day 7.
static void GetDateTime(UInt_t datetime, Int_t &date, Int_t &time)
Static function that returns the date and time.
void FillBuffer(char *&buffer)
Encode Date/Time into buffer, used by I/O system.
void tobuf(char *&buf, Bool_t x)
void Error(const char *location, const char *msgfmt,...)
std::string printValue(const TDatime &val)
Print a TDatime at the prompt.
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
void Print(Option_t *option="") const
Print date and time.
Int_t GetDate() const
Return date in form of 19971224 (i.e. 24/12/1997)
const char * AsString() const
Return the date & time as a string (ctime() format).
const char * AsSQLString() const
Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...