TDatime.h

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TDatime.h 31064 2009-11-10 14:39:38Z rdm $
00002 // Author: Rene Brun   05/01/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TDatime
00013 #define ROOT_TDatime
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TDatime                                                              //
00019 //                                                                      //
00020 // This class stores the date and time with a precision of one second   //
00021 // in an unsigned 32 bit word (e.g. 950130 124559). The date is stored  //
00022 // with the origin being the 1st january 1995.                          //
00023 //                                                                      //
00024 // This class has no support for time zones. The time is assumed        //
00025 // to be in the local time of the machine where the object was created. //
00026 // As a result, TDatime objects are not portable between machines       //
00027 // operating in different time zones and unsuitable for storing the     //
00028 // date/time of data taking events and the like. If absolute time is    //
00029 // required, use TTimeStamp.                                            //
00030 //                                                                      //
00031 //////////////////////////////////////////////////////////////////////////
00032 
00033 #ifndef ROOT_Rtypes
00034 #include "Rtypes.h"
00035 #endif
00036 
00037 
00038 class TDatime {
00039 
00040 private:
00041 
00042 protected:
00043    UInt_t     fDatime;            //Date (relative to 1995) + time
00044 
00045 public:
00046    TDatime();
00047    TDatime(const TDatime &d): fDatime(d.fDatime) { }
00048    TDatime(UInt_t tloc, Bool_t dosDate = kFALSE): fDatime(0)
00049      { Set(tloc, dosDate); }
00050    TDatime(Int_t date, Int_t time);
00051    TDatime(Int_t year, Int_t month, Int_t day,
00052            Int_t hour, Int_t min, Int_t sec);
00053    TDatime(const char *sqlDateTime);
00054    virtual ~TDatime() { }
00055 
00056    TDatime& operator=(const TDatime &d);
00057 
00058    const char  *AsString() const;
00059    const char  *AsString(char *out) const;
00060    const char  *AsSQLString() const;
00061    UInt_t       Convert(Bool_t toGMT = kFALSE) const;
00062    void         Copy(TDatime &datime) const;
00063    UInt_t       Get() const;
00064    Int_t        GetDate() const;
00065    Int_t        GetTime() const;
00066    Int_t        GetYear() const { return (fDatime>>26) + 1995; }
00067    Int_t        GetMonth() const { return (fDatime<<6)>>28; }
00068    Int_t        GetDay() const { return (fDatime<<10)>>27; }
00069    Int_t        GetDayOfWeek() const;
00070    Int_t        GetHour() const { return (fDatime<<15)>>27; }
00071    Int_t        GetMinute() const { return (fDatime<<20)>>26; }
00072    Int_t        GetSecond() const { return (fDatime<<26)>>26; }
00073    void         FillBuffer(char *&buffer);
00074    void         Print(Option_t *option="") const;
00075    void         ReadBuffer(char *&buffer);
00076    void         Set();
00077    void         Set(UInt_t tloc, Bool_t dosDate = kFALSE);
00078    void         Set(Int_t date, Int_t time);
00079    void         Set(Int_t year, Int_t month, Int_t day,
00080                     Int_t hour, Int_t min, Int_t sec);
00081    void         Set(const char *sqlDateTime);
00082    Int_t        Sizeof() const {return sizeof(UInt_t);}
00083 
00084    friend Bool_t operator==(const TDatime &d1, const TDatime &d2);
00085    friend Bool_t operator!=(const TDatime &d1, const TDatime &d2);
00086    friend Bool_t operator< (const TDatime &d1, const TDatime &d2);
00087    friend Bool_t operator<=(const TDatime &d1, const TDatime &d2);
00088    friend Bool_t operator> (const TDatime &d1, const TDatime &d2);
00089    friend Bool_t operator>=(const TDatime &d1, const TDatime &d2);
00090 
00091    static void GetDateTime(UInt_t datetime, Int_t &date, Int_t &time);
00092 
00093    ClassDef(TDatime,1)  //Date and time 950130 124559
00094 };
00095 
00096 
00097 inline TDatime& TDatime::operator=(const TDatime &d)
00098    { fDatime = d.fDatime; return *this; }
00099 
00100 inline Bool_t operator==(const TDatime &d1, const TDatime &d2)
00101    { return d1.fDatime == d2.fDatime; }
00102 inline Bool_t operator!=(const TDatime &d1, const TDatime &d2)
00103    { return d1.fDatime != d2.fDatime; }
00104 inline Bool_t operator< (const TDatime &d1, const TDatime &d2)
00105    { return d1.fDatime < d2.fDatime; }
00106 inline Bool_t operator<=(const TDatime &d1, const TDatime &d2)
00107    { return d1.fDatime <= d2.fDatime; }
00108 inline Bool_t operator> (const TDatime &d1, const TDatime &d2)
00109    { return d1.fDatime > d2.fDatime; }
00110 inline Bool_t operator>=(const TDatime &d1, const TDatime &d2)
00111    { return d1.fDatime >= d2.fDatime; }
00112 
00113 #endif

Generated on Tue Jul 5 14:10:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1