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 16 ////////////////////////////////////////////////////////////////////////// 17 // // 18 // TDatime // 19 // // 20 // This class stores the date and time with a precision of one second // 21 // in an unsigned 32 bit word (e.g. 950130 124559). The date is stored // 22 // with the origin being the 1st january 1995. // 23 // // 24 // This class has no support for time zones. The time is assumed // 25 // to be in the local time of the machine where the object was created. // 26 // As a result, TDatime objects are not portable between machines // 27 // operating in different time zones and unsuitable for storing the // 28 // date/time of data taking events and the like. If absolute time is // 29 // required, use TTimeStamp. // 30 // // 31 ////////////////////////////////////////////////////////////////////////// 32 33 #ifndef ROOT_Rtypes 34 #include "Rtypes.h" 35 #endif 36 37 38 class TDatime { 39 40 private: 41 42 protected: 43 UInt_t fDatime; //Date (relative to 1995) + time 44 45 public: 46 TDatime(); 47 TDatime(const TDatime &d): fDatime(d.fDatime) { } 48 TDatime(UInt_t tloc, Bool_t dosDate = kFALSE): fDatime(0) 49 { Set(tloc, dosDate); } 50 TDatime(Int_t date, Int_t time); 51 TDatime(Int_t year, Int_t month, Int_t day, 52 Int_t hour, Int_t min, Int_t sec); 53 TDatime(const char *sqlDateTime); 54 virtual ~TDatime() { } 55 56 TDatime& operator=(const TDatime &d); 57 58 const char *AsString() const; 59 const char *AsString(char *out) const; 60 const char *AsSQLString() const; 61 UInt_t Convert(Bool_t toGMT = kFALSE) const; 62 void Copy(TDatime &datime) const; 63 UInt_t Get() const; 64 Int_t GetDate() const; 65 Int_t GetTime() const; 66 Int_t GetYear() const { return (fDatime>>26) + 1995; } 67 Int_t GetMonth() const { return (fDatime<<6)>>28; } 68 Int_t GetDay() const { return (fDatime<<10)>>27; } 69 Int_t GetDayOfWeek() const; 70 Int_t GetHour() const { return (fDatime<<15)>>27; } 71 Int_t GetMinute() const { return (fDatime<<20)>>26; } 72 Int_t GetSecond() const { return (fDatime<<26)>>26; } 73 void FillBuffer(char *&buffer); 74 void Print(Option_t *option="") const; 75 void ReadBuffer(char *&buffer); 76 void Set(); 77 void Set(UInt_t tloc, Bool_t dosDate = kFALSE); 78 void Set(Int_t date, Int_t time); 79 void Set(Int_t year, Int_t month, Int_t day, 80 Int_t hour, Int_t min, Int_t sec); 81 void Set(const char *sqlDateTime); 82 Int_t Sizeof() const {return sizeof(UInt_t);} 83 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 friend Bool_t operator>=(const TDatime &d1, const TDatime &d2); 90 91 static void GetDateTime(UInt_t datetime, Int_t &date, Int_t &time); 92 93 ClassDef(TDatime,1) //Date and time 950130 124559 94 }; 95 96 97 inline TDatime& TDatime::operator=(const TDatime &d) 98 { fDatime = d.fDatime; return *this; } 99 100 inline Bool_t operator==(const TDatime &d1, const TDatime &d2) 101 { return d1.fDatime == d2.fDatime; } 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 113 #endif 114