Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
37 class TDatime {
38 
39 private:
40 
41 protected:
42  UInt_t fDatime; //Date (relative to 1995) + time
43 
44 public:
45  TDatime();
46  TDatime(const TDatime &d): fDatime(d.fDatime) { }
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);
92  static Int_t GetDateFromGlobalDay(Int_t day);
93  static Int_t GetLegalGlobalDayFromDate(Int_t date);
94 
95  ClassDef(TDatime,1) //Date and time 950130 124559
96 };
97 
98 
99 inline TDatime& TDatime::operator=(const TDatime &d)
100  { fDatime = d.fDatime; return *this; }
101 
102 inline Bool_t operator==(const TDatime &d1, const TDatime &d2)
103  { return d1.fDatime == d2.fDatime; }
104 inline Bool_t operator!=(const TDatime &d1, const TDatime &d2)
105  { return d1.fDatime != d2.fDatime; }
106 inline Bool_t operator< (const TDatime &d1, const TDatime &d2)
107  { return d1.fDatime < d2.fDatime; }
108 inline Bool_t operator<=(const TDatime &d1, const TDatime &d2)
109  { return d1.fDatime <= d2.fDatime; }
110 inline Bool_t operator> (const TDatime &d1, const TDatime &d2)
111  { return d1.fDatime > d2.fDatime; }
112 inline Bool_t operator>=(const TDatime &d1, const TDatime &d2)
113  { return d1.fDatime >= d2.fDatime; }
114 
115 namespace cling {
116  std::string printValue(const TDatime* val);
117 }
118 #endif