ROOT  6.06/09
Reference Guide
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 #ifndef ROOT_Rtypes
35 #include "Rtypes.h"
36 #endif
37 
38 
39 class TDatime {
40 
41 private:
42 
43 protected:
44  UInt_t fDatime; //Date (relative to 1995) + time
45 
46 public:
47  TDatime();
48  TDatime(const TDatime &d): fDatime(d.fDatime) { }
49  TDatime(UInt_t tloc, Bool_t dosDate = kFALSE): fDatime(0)
50  { Set(tloc, dosDate); }
51  TDatime(Int_t date, Int_t time);
52  TDatime(Int_t year, Int_t month, Int_t day,
53  Int_t hour, Int_t min, Int_t sec);
54  TDatime(const char *sqlDateTime);
55  virtual ~TDatime() { }
56 
57  TDatime& operator=(const TDatime &d);
58 
59  const char *AsString() const;
60  const char *AsString(char *out) const;
61  const char *AsSQLString() const;
62  UInt_t Convert(Bool_t toGMT = kFALSE) const;
63  void Copy(TDatime &datime) const;
64  UInt_t Get() const;
65  Int_t GetDate() const;
66  Int_t GetTime() const;
67  Int_t GetYear() const { return (fDatime>>26) + 1995; }
68  Int_t GetMonth() const { return (fDatime<<6)>>28; }
69  Int_t GetDay() const { return (fDatime<<10)>>27; }
70  Int_t GetDayOfWeek() const;
71  Int_t GetHour() const { return (fDatime<<15)>>27; }
72  Int_t GetMinute() const { return (fDatime<<20)>>26; }
73  Int_t GetSecond() const { return (fDatime<<26)>>26; }
74  void FillBuffer(char *&buffer);
75  void Print(Option_t *option="") const;
76  void ReadBuffer(char *&buffer);
77  void Set();
78  void Set(UInt_t tloc, Bool_t dosDate = kFALSE);
79  void Set(Int_t date, Int_t time);
80  void Set(Int_t year, Int_t month, Int_t day,
81  Int_t hour, Int_t min, Int_t sec);
82  void Set(const char *sqlDateTime);
83  Int_t Sizeof() const {return sizeof(UInt_t);}
84 
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  friend Bool_t operator> (const TDatime &d1, const TDatime &d2);
90  friend Bool_t operator>=(const TDatime &d1, const TDatime &d2);
91 
92  static void GetDateTime(UInt_t datetime, Int_t &date, Int_t &time);
93 
94  ClassDef(TDatime,1) //Date and time 950130 124559
95 };
96 
97 
99  { fDatime = d.fDatime; return *this; }
100 
101 inline Bool_t operator==(const TDatime &d1, const TDatime &d2)
102  { return d1.fDatime == d2.fDatime; }
103 inline Bool_t operator!=(const TDatime &d1, const TDatime &d2)
104  { return d1.fDatime != d2.fDatime; }
105 inline Bool_t operator< (const TDatime &d1, const TDatime &d2)
106  { return d1.fDatime < d2.fDatime; }
107 inline Bool_t operator<=(const TDatime &d1, const TDatime &d2)
108  { return d1.fDatime <= d2.fDatime; }
109 inline Bool_t operator> (const TDatime &d1, const TDatime &d2)
110  { return d1.fDatime > d2.fDatime; }
111 inline Bool_t operator>=(const TDatime &d1, const TDatime &d2)
112  { return d1.fDatime >= d2.fDatime; }
113 
114 namespace cling {
115  std::string printValue(const TDatime &val);
116 }
117 #endif
Bool_t operator<(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:105
Int_t GetMonth() const
Definition: TDatime.h:68
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:179
void Set()
Set Date/Time to current time as reported by the system.
Definition: TDatime.cxx:286
void Copy(TDatime &datime) const
Copy this to datime.
Definition: TDatime.cxx:218
friend Bool_t operator>(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:109
const char Option_t
Definition: RtypesCore.h:62
UInt_t Get() const
Return raw date/time as encoded by TDatime.
Definition: TDatime.cxx:237
friend Bool_t operator<=(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:107
friend Bool_t operator<(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:105
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TDatime(const TDatime &d)
Definition: TDatime.h:48
void ReadBuffer(char *&buffer)
Decode Date/Time from output buffer, used by I/O system.
Definition: TDatime.cxx:275
friend Bool_t operator>=(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:111
#define ClassDef(name, id)
Definition: Rtypes.h:254
Int_t GetDay() const
Definition: TDatime.h:69
Int_t GetTime() const
Return time in form of 123623 (i.e. 12:36:23)
Definition: TDatime.cxx:256
Int_t GetDayOfWeek() const
Returns day of week, with Monday being day 1 and Sunday day 7.
Definition: TDatime.cxx:83
static void GetDateTime(UInt_t datetime, Int_t &date, Int_t &time)
Static function that returns the date and time.
Definition: TDatime.cxx:432
void FillBuffer(char *&buffer)
Encode Date/Time into buffer, used by I/O system.
Definition: TDatime.cxx:226
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:103
char * out
Definition: TBase64.cxx:29
std::string printValue(const TDatime &val)
Print a TDatime at the prompt.
Definition: TDatime.cxx:447
virtual ~TDatime()
Definition: TDatime.h:55
Bool_t operator>(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:109
Int_t Sizeof() const
Definition: TDatime.h:83
Int_t GetHour() const
Definition: TDatime.h:71
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t GetSecond() const
Definition: TDatime.h:73
TDatime(UInt_t tloc, Bool_t dosDate=kFALSE)
Definition: TDatime.h:49
Int_t GetYear() const
Definition: TDatime.h:67
friend Bool_t operator==(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:101
Int_t GetMinute() const
Definition: TDatime.h:72
Definition: TDatime.h:114
void Print(Option_t *option="") const
Print date and time.
Definition: TDatime.cxx:267
TDatime & operator=(const TDatime &d)
Definition: TDatime.h:98
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:101
Int_t GetDate() const
Return date in form of 19971224 (i.e. 24/12/1997)
Definition: TDatime.cxx:245
friend Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:103
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition: TDatime.cxx:99
UInt_t fDatime
Definition: TDatime.h:44
const char * AsSQLString() const
Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28.
Definition: TDatime.cxx:149
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:39
Bool_t operator>=(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:111
Bool_t operator<=(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:107