Logo ROOT   6.16/01
Reference Guide
List of all members | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
TDatime Class Reference

This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130 124559).

The date is stored with the origin being the 1st January 1995.

This class has no support for time zones. The time is assumed to be in the local time of the machine where the object was created. As a result, TDatime objects are not portable between machines operating in different time zones and unsuitable for storing the date/time of data taking events and the like. If absolute time is required, use TTimeStamp.

Definition at line 37 of file TDatime.h.

Public Member Functions

 TDatime ()
 Create a TDatime and set it to the current time. More...
 
 TDatime (const char *sqlDateTime)
 Expects as input a string in SQL date/time compatible format, like: yyyy-mm-dd hh:mm:ss. More...
 
 TDatime (const TDatime &d)
 
 TDatime (Int_t date, Int_t time)
 Create a TDatime and set it to the specified date and time. More...
 
 TDatime (Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec)
 Create a TDatime and set it to the specified year, month, day, time, hour, minute and second. More...
 
 TDatime (UInt_t tloc, Bool_t dosDate=kFALSE)
 
virtual ~TDatime ()
 
const char * AsSQLString () const
 Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28. More...
 
const char * AsString () const
 Return the date & time as a string (ctime() format). More...
 
const char * AsString (char *out) const
 Return the date & time as a string (ctime() format). More...
 
UInt_t Convert (Bool_t toGMT=kFALSE) const
 Convert fDatime from TDatime format to the standard time_t format. More...
 
void Copy (TDatime &datime) const
 Copy this to datime. More...
 
void FillBuffer (char *&buffer)
 Encode Date/Time into buffer, used by I/O system. More...
 
UInt_t Get () const
 Return raw date/time as encoded by TDatime. More...
 
Int_t GetDate () const
 Return date in form of 19971224 (i.e. 24/12/1997) More...
 
Int_t GetDay () const
 
Int_t GetDayOfWeek () const
 Returns day of week, with Monday being day 1 and Sunday day 7. More...
 
Int_t GetHour () const
 
Int_t GetMinute () const
 
Int_t GetMonth () const
 
Int_t GetSecond () const
 
Int_t GetTime () const
 Return time in form of 123623 (i.e. 12:36:23) More...
 
Int_t GetYear () const
 
TDatimeoperator= (const TDatime &d)
 
void Print (Option_t *option="") const
 Print date and time. More...
 
void ReadBuffer (char *&buffer)
 Decode Date/Time from output buffer, used by I/O system. More...
 
void Set ()
 Set Date/Time to current time as reported by the system. More...
 
void Set (const char *sqlDateTime)
 Expects as input a string in SQL date/time compatible format, like: yyyy-mm-dd hh:mm:ss. More...
 
void Set (Int_t date, Int_t time)
 Set date and time. More...
 
void Set (Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec)
 Set date and time. More...
 
void Set (UInt_t tloc, Bool_t dosDate=kFALSE)
 The input arg is a time_t value returned by time() or a value returned by Convert(). More...
 
Int_t Sizeof () const
 

Static Public Member Functions

static Int_t GetDateFromGlobalDay (Int_t day)
 Static function that returns the date from the global day number. More...
 
static void GetDateTime (UInt_t datetime, Int_t &date, Int_t &time)
 Static function that returns the date and time. More...
 
static Int_t GetGlobalDayFromDate (Int_t date)
 Static function that returns the global day number from date. More...
 
static Int_t GetLegalGlobalDayFromDate (Int_t date)
 Static function that returns the global day number from date. More...
 

Protected Attributes

UInt_t fDatime
 

Friends

Bool_t operator!= (const TDatime &d1, const TDatime &d2)
 
Bool_t operator< (const TDatime &d1, const TDatime &d2)
 
Bool_t operator<= (const TDatime &d1, const TDatime &d2)
 
Bool_t operator== (const TDatime &d1, const TDatime &d2)
 
Bool_t operator> (const TDatime &d1, const TDatime &d2)
 
Bool_t operator>= (const TDatime &d1, const TDatime &d2)
 

#include <TDatime.h>

Constructor & Destructor Documentation

◆ TDatime() [1/6]

TDatime::TDatime ( )

Create a TDatime and set it to the current time.

Definition at line 49 of file TDatime.cxx.

◆ TDatime() [2/6]

TDatime::TDatime ( const TDatime d)
inline

Definition at line 46 of file TDatime.h.

◆ TDatime() [3/6]

TDatime::TDatime ( UInt_t  tloc,
Bool_t  dosDate = kFALSE 
)
inline

Definition at line 47 of file TDatime.h.

◆ TDatime() [4/6]

TDatime::TDatime ( Int_t  date,
Int_t  time 
)

Create a TDatime and set it to the specified date and time.

See Set(Int_t, Int_t) about the date, time format.

Definition at line 58 of file TDatime.cxx.

◆ TDatime() [5/6]

TDatime::TDatime ( Int_t  year,
Int_t  month,
Int_t  day,
Int_t  hour,
Int_t  min,
Int_t  sec 
)

Create a TDatime and set it to the specified year, month, day, time, hour, minute and second.

See Set() about the format.

Definition at line 67 of file TDatime.cxx.

◆ TDatime() [6/6]

TDatime::TDatime ( const char *  sqlDateTime)

Expects as input a string in SQL date/time compatible format, like: yyyy-mm-dd hh:mm:ss.

Definition at line 77 of file TDatime.cxx.

◆ ~TDatime()

virtual TDatime::~TDatime ( )
inlinevirtual

Definition at line 53 of file TDatime.h.

Member Function Documentation

◆ AsSQLString()

const char * TDatime::AsSQLString ( ) const

Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28.

The returned string buffer is static and will be reused.

Definition at line 151 of file TDatime.cxx.

◆ AsString() [1/2]

const char * TDatime::AsString ( ) const

Return the date & time as a string (ctime() format).

Copy result because it points to a statically allocated string.

Definition at line 101 of file TDatime.cxx.

◆ AsString() [2/2]

const char * TDatime::AsString ( char *  out) const

Return the date & time as a string (ctime() format).

Result is copied into out (and out is returned). Make sure out can at least contain 26 characters. Thread safe.

Definition at line 120 of file TDatime.cxx.

◆ Convert()

UInt_t TDatime::Convert ( Bool_t  toGMT = kFALSE) const

Convert fDatime from TDatime format to the standard time_t format.

If toGMT is true, the time offset of the current local time zone is subtracted from the returned time_t. One use of such a non-standard time_t value is to convert a TDatime object that contains local time to GMT, as in this example:

TDatime now;
now.Set(now.Convert(kTRUE));
const Bool_t kTRUE
Definition: RtypesCore.h:87
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
void Set()
Set Date/Time to current time as reported by the system.
Definition: TDatime.cxx:288
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:181

Caution: the time_t returned from Convert(kTRUE) is incompatible with regular Unix time - it contains an artificial, locale-dependent offset.

Definition at line 181 of file TDatime.cxx.

◆ Copy()

void TDatime::Copy ( TDatime datime) const

Copy this to datime.

Definition at line 220 of file TDatime.cxx.

◆ FillBuffer()

void TDatime::FillBuffer ( char *&  buffer)

Encode Date/Time into buffer, used by I/O system.

Definition at line 228 of file TDatime.cxx.

◆ Get()

UInt_t TDatime::Get ( ) const

Return raw date/time as encoded by TDatime.

Note, this value cannot be used to e.g. calculate time differences, as it is an encoded value. To calculate time differences use the Convert() method to get a time in seconds and then subtract the values.

Definition at line 239 of file TDatime.cxx.

◆ GetDate()

Int_t TDatime::GetDate ( ) const

Return date in form of 19971224 (i.e. 24/12/1997)

Definition at line 247 of file TDatime.cxx.

◆ GetDateFromGlobalDay()

Int_t TDatime::GetDateFromGlobalDay ( Int_t  day)
static

Static function that returns the date from the global day number.

The output is in TDatime yyyymmdd format (as obtained via TDatime::GetDate()).

Definition at line 469 of file TDatime.cxx.

◆ GetDateTime()

void TDatime::GetDateTime ( UInt_t  datetime,
Int_t date,
Int_t time 
)
static

Static function that returns the date and time.

The input is in TDatime format (as obtained via TDatime::Get()). Date is returned in the format 950223 February 23 1995. Time is returned in the format 102459 10h 24m 59s.

Definition at line 434 of file TDatime.cxx.

◆ GetDay()

Int_t TDatime::GetDay ( ) const
inline

Definition at line 67 of file TDatime.h.

◆ GetDayOfWeek()

Int_t TDatime::GetDayOfWeek ( ) const

Returns day of week, with Monday being day 1 and Sunday day 7.

Definition at line 85 of file TDatime.cxx.

◆ GetGlobalDayFromDate()

Int_t TDatime::GetGlobalDayFromDate ( Int_t  date)
static

Static function that returns the global day number from date.

The input is in TDatime format yyyymmdd (as obtained via TDatime::GetDate()). This algorithm is only accurate for dates later than October 1582 (earliest date on Gregorian calendar).

Definition at line 452 of file TDatime.cxx.

◆ GetHour()

Int_t TDatime::GetHour ( ) const
inline

Definition at line 69 of file TDatime.h.

◆ GetLegalGlobalDayFromDate()

Int_t TDatime::GetLegalGlobalDayFromDate ( Int_t  date)
static

Static function that returns the global day number from date.

The input is in TDatime format yyyymmdd (as obtained via TDatime::GetDate()). This algorithm is only accurate for dates later than October 1582 (earliest date on Gregorian calendar) and it is checked that the date is larger than 15821001 and conversion is correct. In case of conversion failure 0 is returned. No need to use when you know dates are larger than October 1582.

Definition at line 495 of file TDatime.cxx.

◆ GetMinute()

Int_t TDatime::GetMinute ( ) const
inline

Definition at line 70 of file TDatime.h.

◆ GetMonth()

Int_t TDatime::GetMonth ( ) const
inline

Definition at line 66 of file TDatime.h.

◆ GetSecond()

Int_t TDatime::GetSecond ( ) const
inline

Definition at line 71 of file TDatime.h.

◆ GetTime()

Int_t TDatime::GetTime ( ) const

Return time in form of 123623 (i.e. 12:36:23)

Definition at line 258 of file TDatime.cxx.

◆ GetYear()

Int_t TDatime::GetYear ( ) const
inline

Definition at line 65 of file TDatime.h.

◆ operator=()

TDatime & TDatime::operator= ( const TDatime d)
inline

Definition at line 99 of file TDatime.h.

◆ Print()

void TDatime::Print ( Option_t option = "") const

Print date and time.

Definition at line 269 of file TDatime.cxx.

◆ ReadBuffer()

void TDatime::ReadBuffer ( char *&  buffer)

Decode Date/Time from output buffer, used by I/O system.

Definition at line 277 of file TDatime.cxx.

◆ Set() [1/5]

void TDatime::Set ( )

Set Date/Time to current time as reported by the system.

Date and Time are encoded into one single unsigned 32 bit word. Date is stored with the origin being the 1st January 1995. Time has 1 second precision.

Definition at line 288 of file TDatime.cxx.

◆ Set() [2/5]

void TDatime::Set ( const char *  sqlDateTime)

Expects as input a string in SQL date/time compatible format, like: yyyy-mm-dd hh:mm:ss.

Definition at line 403 of file TDatime.cxx.

◆ Set() [3/5]

void TDatime::Set ( Int_t  date,
Int_t  time 
)

Set date and time.

Data must be in format 980418 or 19980418 and time in 224512 (second precision). The date must be >= 950101.

For years >= 2000, date can be given in the form 20001127 or 1001127 internally the date will be converted to 1001127

Definition at line 362 of file TDatime.cxx.

◆ Set() [4/5]

void TDatime::Set ( Int_t  year,
Int_t  month,
Int_t  day,
Int_t  hour,
Int_t  min,
Int_t  sec 
)

Set date and time.

Year may be xx where 95 <= xx <= 158 (158 being 2058). The year must be >= 1995.

Definition at line 387 of file TDatime.cxx.

◆ Set() [5/5]

void TDatime::Set ( UInt_t  tloc,
Bool_t  dosDate = kFALSE 
)

The input arg is a time_t value returned by time() or a value returned by Convert().

This value is the number of seconds since the EPOCH (i.e. 00:00:00 on Jan 1m 1970). If dosDate is true then the input is a dosDate value.

Definition at line 324 of file TDatime.cxx.

◆ Sizeof()

Int_t TDatime::Sizeof ( ) const
inline

Definition at line 81 of file TDatime.h.

Friends And Related Function Documentation

◆ operator!=

Bool_t operator!= ( const TDatime d1,
const TDatime d2 
)
friend

Definition at line 104 of file TDatime.h.

◆ operator<

Bool_t operator< ( const TDatime d1,
const TDatime d2 
)
friend

Definition at line 106 of file TDatime.h.

◆ operator<=

Bool_t operator<= ( const TDatime d1,
const TDatime d2 
)
friend

Definition at line 108 of file TDatime.h.

◆ operator==

Bool_t operator== ( const TDatime d1,
const TDatime d2 
)
friend

Definition at line 102 of file TDatime.h.

◆ operator>

Bool_t operator> ( const TDatime d1,
const TDatime d2 
)
friend

Definition at line 110 of file TDatime.h.

◆ operator>=

Bool_t operator>= ( const TDatime d1,
const TDatime d2 
)
friend

Definition at line 112 of file TDatime.h.

Member Data Documentation

◆ fDatime

UInt_t TDatime::fDatime
protected

Definition at line 42 of file TDatime.h.


The documentation for this class was generated from the following files: