Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TDatime.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/base:$Id$
0002 // Author: Rene Brun   05/01/95
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TDatime
0013 #define ROOT_TDatime
0014 
0015 #include <string>
0016 
0017 //////////////////////////////////////////////////////////////////////////
0018 //                                                                      //
0019 // TDatime                                                              //
0020 //                                                                      //
0021 // This class stores the date and time with a precision of one second   //
0022 // in an unsigned 32 bit word (e.g. 950130 124559). The date is stored  //
0023 // with the origin being the 1st january 1995.                          //
0024 //                                                                      //
0025 // This class has no support for time zones. The time is assumed        //
0026 // to be in the local time of the machine where the object was created. //
0027 // As a result, TDatime objects are not portable between machines       //
0028 // operating in different time zones and unsuitable for storing the     //
0029 // date/time of data taking events and the like. If absolute time is    //
0030 // required, use TTimeStamp.                                            //
0031 //                                                                      //
0032 //////////////////////////////////////////////////////////////////////////
0033 
0034 #include "Rtypes.h"
0035 
0036 
0037 class TDatime {
0038 
0039 private:
0040 
0041 protected:
0042    UInt_t     fDatime;            //Date (relative to 1995) + time
0043 
0044 public:
0045    TDatime();
0046    TDatime(const TDatime &d): fDatime(d.fDatime) { }
0047    TDatime(UInt_t tloc, Bool_t dosDate = kFALSE): fDatime(0)
0048      { Set(tloc, dosDate); }
0049    TDatime(Int_t date, Int_t time);
0050    TDatime(Int_t year, Int_t month, Int_t day,
0051            Int_t hour, Int_t min, Int_t sec);
0052    TDatime(const char *sqlDateTime);
0053    virtual ~TDatime() { }
0054 
0055    TDatime& operator=(const TDatime &d);
0056 
0057    const char  *AsString() const;
0058    const char  *AsString(char *out) const;
0059    const char  *AsSQLString() const;
0060    UInt_t       Convert(Bool_t toGMT = kFALSE) const;
0061    void         Copy(TDatime &datime) const;
0062    UInt_t       Get() const;
0063    Int_t        GetDate() const;
0064    Int_t        GetTime() const;
0065    Int_t        GetYear() const { return (fDatime>>26) + 1995; }
0066    Int_t        GetMonth() const { return (fDatime<<6)>>28; }
0067    Int_t        GetDay() const { return (fDatime<<10)>>27; }
0068    Int_t        GetDayOfWeek() const;
0069    Int_t        GetHour() const { return (fDatime<<15)>>27; }
0070    Int_t        GetMinute() const { return (fDatime<<20)>>26; }
0071    Int_t        GetSecond() const { return (fDatime<<26)>>26; }
0072    void         FillBuffer(char *&buffer);
0073    void         Print(Option_t *option="") const;
0074    void         ReadBuffer(char *&buffer);
0075    void         Set();
0076    void         Set(UInt_t tloc, Bool_t dosDate = kFALSE);
0077    void         Set(Int_t date, Int_t time);
0078    void         Set(Int_t year, Int_t month, Int_t day,
0079                     Int_t hour, Int_t min, Int_t sec);
0080    void         Set(const char *sqlDateTime);
0081    Int_t        Sizeof() const {return sizeof(UInt_t);}
0082 
0083    friend Bool_t operator==(const TDatime &d1, const TDatime &d2);
0084    friend Bool_t operator!=(const TDatime &d1, const TDatime &d2);
0085    friend Bool_t operator< (const TDatime &d1, const TDatime &d2);
0086    friend Bool_t operator<=(const TDatime &d1, const TDatime &d2);
0087    friend Bool_t operator> (const TDatime &d1, const TDatime &d2);
0088    friend Bool_t operator>=(const TDatime &d1, const TDatime &d2);
0089 
0090    static void  GetDateTime(UInt_t datetime, Int_t &date, Int_t &time);
0091    static Int_t GetGlobalDayFromDate(Int_t date);
0092    static Int_t GetDateFromGlobalDay(Int_t day);
0093    static Int_t GetLegalGlobalDayFromDate(Int_t date);
0094 
0095    ClassDef(TDatime,1)  //Date and time 950130 124559
0096 };
0097 
0098 
0099 inline TDatime& TDatime::operator=(const TDatime &d)
0100    { fDatime = d.fDatime; return *this; }
0101 
0102 inline Bool_t operator==(const TDatime &d1, const TDatime &d2)
0103    { return d1.fDatime == d2.fDatime; }
0104 inline Bool_t operator!=(const TDatime &d1, const TDatime &d2)
0105    { return d1.fDatime != d2.fDatime; }
0106 inline Bool_t operator< (const TDatime &d1, const TDatime &d2)
0107    { return d1.fDatime < d2.fDatime; }
0108 inline Bool_t operator<=(const TDatime &d1, const TDatime &d2)
0109    { return d1.fDatime <= d2.fDatime; }
0110 inline Bool_t operator> (const TDatime &d1, const TDatime &d2)
0111    { return d1.fDatime > d2.fDatime; }
0112 inline Bool_t operator>=(const TDatime &d1, const TDatime &d2)
0113    { return d1.fDatime >= d2.fDatime; }
0114 
0115 namespace cling {
0116   std::string printValue(const TDatime* val);
0117 }
0118 #endif