LCIO  "2.7.4"
 All Classes Namespaces Functions Variables Typedefs Friends Pages
LCTime.h
1 // -*- C++ -*-
2 #ifndef UTIL_LCTIME_H
3 #define UTIL_LCTIME_H 1
4 
5 #include "LCIOTypes.h"
6 
7 namespace UTIL {
8 
19  class LCTime {
20 
21  public:
24  struct CalendarTime{
25  short year ;
26  short month ;
27  short day ;
28  short hour ;
29  short min ;
30  short sec ;
31  int ns ;
32  } ;
33 
34  public:
35 
38  LCTime() ;
39 
42  LCTime( EVENT::long64 time ) ;
43 
46  LCTime(int year, int month, int day, int hour=0, int min=0, int s=0 ) ;
47 
50  LCTime( int unixTime ) ;
51 
52 
55  int unixTime() const { return ( _t / 1000000000LL ) ; }
56 
59  EVENT::long64 timeStamp() const { return _t ; }
60 
61 
66  bool isLeapYear( int year ) const { return ( ( !( year % 4 ) && ( year%100 ) ) || !(year%400) ) ; }
67 
69  int daysInYear( int year ) const ;
70 
72  int daysInMonth( int month , int year ) const ;
73 
77  std::string getDateString() const ;
78 
81  const CalendarTime& calendarTime() const { return _d ; }
82 
84  int year() const { return _d.year ; }
85 
87  int month() const { return _d.month ; }
88 
90  int day() const { return _d.day ; }
91 
93  int hour() const { return _d.hour ; }
94 
96  int min() const { return _d.min ; }
97 
99  int sec() const { return _d.sec ; }
100 
102  int ns() const { return _d.ns ; }
103 
106  void operator+=(EVENT::long64 t) ;
107 
108 
109  virtual ~LCTime() { /*no_op*/; }
110 
111 
115  static bool test( int nDates ) ;
116 
117  protected:
118 
119  EVENT::long64 _t ; // time stamp in ns
120  CalendarTime _d ; // calendar date and time
121 
122 
123  // internal helper methods
124  void convertToCalTime() ;
125 
126  void convertFromCalTime() ;
127 
128  static int dpm[13] ; // days per month
129 
130  }; // class
131 
132 
133 } // namespace UTIL
134 
135 #endif /* ifndef UTIL_LCTIME_H */
int year() const
Calendar time: year.
Definition: LCTime.h:84
int sec() const
Calendar time: sec.
Definition: LCTime.h:99
int daysInMonth(int month, int year) const
The number if days in the given month and year in the Gregorian calendar.
Definition: LCTime.cc:202
int daysInYear(int year) const
The number if days in the given year in the Gregorian calendar.
Definition: LCTime.cc:196
int unixTime() const
Unix time ( s since 1.1.1970 00:00:00 ).
Definition: LCTime.h:55
long long long64
64 bit signed integer,e.g.to be used for timestamps
Definition: LCIOTypes.h:14
Helper class that allows to convert time stamps as defined in LCEvent::getTimeStamp() ( ns since 1...
Definition: LCTime.h:19
int month() const
Calendar time: month.
Definition: LCTime.h:87
int ns() const
Calendar time: ns.
Definition: LCTime.h:102
std::string getDateString() const
Date in human readable format, e.g.
Definition: LCTime.cc:220
EVENT::long64 timeStamp() const
64bit time stamp as used in LCEvent::getTimestamp().
Definition: LCTime.h:59
int day() const
Calendar time: day.
Definition: LCTime.h:90
int hour() const
Calendar time: hour.
Definition: LCTime.h:93
int min() const
Calendar time: min.
Definition: LCTime.h:96
const CalendarTime & calendarTime() const
Calendar time: year,month,day hour,min,sec and ns.
Definition: LCTime.h:81
void operator+=(EVENT::long64 t)
Add the specified number of ns to the time.
Definition: LCTime.cc:213
static bool test(int nDates)
Tests the LCTime class with nDates random dates Returns true if successful - throws Exception in case...
Definition: LCTime.cc:244
LCTime()
Init with current time ( accuracy depends on OS/machine,etc.) in UTC/GMT.
Definition: LCTime.cc:30
bool isLeapYear(int year) const
True if the year is a leap year in the Gregorian calendar: year is multiple of 4 and not multiple of...
Definition: LCTime.h:66
Helper struct that holds the calendar time.
Definition: LCTime.h:24