Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TDatime.h
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Rene Brun 05/01/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TDatime
13#define ROOT_TDatime
14
15#include <string>
16
17//////////////////////////////////////////////////////////////////////////
18// //
19// TDatime //
20// //
21// This class stores the date and time with a precision of one second //
22// in an unsigned 32 bit word (e.g. 950130 124559). The date is stored //
23// with the origin being the 1st january 1995. //
24// //
25// This class has no support for time zones. The time is assumed //
26// to be in the local time of the machine where the object was created. //
27// As a result, TDatime objects are not portable between machines //
28// operating in different time zones and unsuitable for storing the //
29// date/time of data taking events and the like. If absolute time is //
30// required, use TTimeStamp. //
31// //
32//////////////////////////////////////////////////////////////////////////
33
34#include "Rtypes.h"
35
36
37class TDatime {
38
39private:
40
41protected:
42 UInt_t fDatime; //Date (relative to 1995) + time
43
44public:
45 TDatime();
47 TDatime(UInt_t tloc, Bool_t dosDate = kFALSE): fDatime(0)
48 { Set(tloc, dosDate); }
49 TDatime(Int_t date, Int_t time);
50 TDatime(Int_t year, Int_t month, Int_t day,
51 Int_t hour, Int_t min, Int_t sec);
52 TDatime(const char *sqlDateTime);
53 virtual ~TDatime() { }
54
55 TDatime& operator=(const TDatime &d);
56
57 const char *AsString() const;
58 const char *AsString(char *out) const;
59 const char *AsSQLString() const;
60 UInt_t Convert(Bool_t toGMT = kFALSE) const;
61 void Copy(TDatime &datime) const;
62 UInt_t Get() const;
63 Int_t GetDate() const;
64 Int_t GetTime() const;
65 Int_t GetYear() const { return (fDatime>>26) + 1995; }
66 Int_t GetMonth() const { return (fDatime<<6)>>28; }
67 Int_t GetDay() const { return (fDatime<<10)>>27; }
68 Int_t GetDayOfWeek() const;
69 Int_t GetHour() const { return (fDatime<<15)>>27; }
70 Int_t GetMinute() const { return (fDatime<<20)>>26; }
71 Int_t GetSecond() const { return (fDatime<<26)>>26; }
72 void FillBuffer(char *&buffer);
73 void Print(Option_t *option="") const;
74 void ReadBuffer(char *&buffer);
75 void Set();
76 void Set(UInt_t tloc, Bool_t dosDate = kFALSE);
77 void Set(Int_t date, Int_t time);
78 void Set(Int_t year, Int_t month, Int_t day,
79 Int_t hour, Int_t min, Int_t sec);
80 void Set(const char *sqlDateTime);
81 Int_t Sizeof() const {return sizeof(UInt_t);}
82
83 friend Bool_t operator==(const TDatime &d1, const TDatime &d2);
84 friend Bool_t operator!=(const TDatime &d1, const TDatime &d2);
85 friend Bool_t operator< (const TDatime &d1, const TDatime &d2);
86 friend Bool_t operator<=(const TDatime &d1, const TDatime &d2);
87 friend Bool_t operator> (const TDatime &d1, const TDatime &d2);
88 friend Bool_t operator>=(const TDatime &d1, const TDatime &d2);
89
90 static void GetDateTime(UInt_t datetime, Int_t &date, Int_t &time);
91 static Int_t GetGlobalDayFromDate(Int_t date);
94
95 ClassDef(TDatime,1) //Date and time 950130 124559
96};
97
98
100 { fDatime = d.fDatime; return *this; }
101
102inline Bool_t operator==(const TDatime &d1, const TDatime &d2)
103 { return d1.fDatime == d2.fDatime; }
104inline Bool_t operator!=(const TDatime &d1, const TDatime &d2)
105 { return d1.fDatime != d2.fDatime; }
106inline Bool_t operator< (const TDatime &d1, const TDatime &d2)
107 { return d1.fDatime < d2.fDatime; }
108inline Bool_t operator<=(const TDatime &d1, const TDatime &d2)
109 { return d1.fDatime <= d2.fDatime; }
110inline Bool_t operator> (const TDatime &d1, const TDatime &d2)
111 { return d1.fDatime > d2.fDatime; }
112inline Bool_t operator>=(const TDatime &d1, const TDatime &d2)
113 { return d1.fDatime >= d2.fDatime; }
114
115namespace cling {
116 std::string printValue(const TDatime* val);
117}
118#endif
#define d(i)
Definition RSha256.hxx:102
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:337
Bool_t operator<=(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:108
Bool_t operator>(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:110
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:104
Bool_t operator>=(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:112
Bool_t operator<(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:106
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:102
Option_t Option_t option
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
Int_t GetMonth() const
Definition TDatime.h:66
Int_t GetDay() const
Definition TDatime.h:67
static Int_t GetGlobalDayFromDate(Int_t date)
Static function that returns the global day number from date.
Definition TDatime.cxx:449
static Int_t GetDateFromGlobalDay(Int_t day)
Static function that returns the date from the global day number.
Definition TDatime.cxx:466
void Copy(TDatime &datime) const
Copy this to datime.
Definition TDatime.cxx:221
Int_t GetHour() const
Definition TDatime.h:69
static Int_t GetLegalGlobalDayFromDate(Int_t date)
Static function that returns the global day number from date.
Definition TDatime.cxx:492
friend Bool_t operator<=(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:108
Int_t GetDate() const
Return date in form of 19971224 (i.e. 24/12/1997)
Definition TDatime.cxx:248
virtual ~TDatime()
Definition TDatime.h:53
UInt_t Get() const
Return raw date/time as encoded by TDatime.
Definition TDatime.cxx:240
TDatime(const TDatime &d)
Definition TDatime.h:46
void FillBuffer(char *&buffer)
Encode Date/Time into buffer, used by I/O system.
Definition TDatime.cxx:229
Int_t GetDayOfWeek() const
Returns day of week, with Monday being day 1 and Sunday day 7.
Definition TDatime.cxx:86
void Print(Option_t *option="") const
Print date and time.
Definition TDatime.cxx:270
Int_t GetSecond() const
Definition TDatime.h:71
friend Bool_t operator>(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:110
const char * AsSQLString() const
Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28.
Definition TDatime.cxx:152
Int_t GetYear() const
Definition TDatime.h:65
Int_t Sizeof() const
Definition TDatime.h:81
TDatime(UInt_t tloc, Bool_t dosDate=kFALSE)
Definition TDatime.h:47
Int_t GetMinute() const
Definition TDatime.h:70
friend Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:104
TDatime()
Create a TDatime and set it to the current time.
Definition TDatime.cxx:50
void Set()
Set Date/Time to current time as reported by the system.
Definition TDatime.cxx:289
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition TDatime.cxx:182
UInt_t fDatime
Definition TDatime.h:42
friend Bool_t operator>=(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:112
Int_t GetTime() const
Return time in form of 123623 (i.e. 12:36:23)
Definition TDatime.cxx:259
friend Bool_t operator<(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:106
TDatime & operator=(const TDatime &d)
Definition TDatime.h:99
friend Bool_t operator==(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:102
static void GetDateTime(UInt_t datetime, Int_t &date, Int_t &time)
Static function that returns the date and time.
Definition TDatime.cxx:431
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition TDatime.cxx:102
void ReadBuffer(char *&buffer)
Decode Date/Time from output buffer, used by I/O system.
Definition TDatime.cxx:278