All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Time.h
Go to the documentation of this file.
1 // $Id: Time.h,v 1.3 2006/01/25 16:02:48 hmd Exp $
2 #ifndef GAUDIKERNEL_TIME_H
3 #define GAUDIKERNEL_TIME_H 1
4 
5 // Include files
6 // for the architecture independent int64 definition (longlong)
7 #include "GaudiKernel/Kernel.h"
10 
22 public:
23  // Standard constructor
24  TimeException( const std::string& Message = "unspecified exception",
25  const std::string& Tag = "*Gaudi::Time*",
26  const StatusCode & Code = StatusCode::FAILURE ):
27  GaudiException(Message,Tag,Code) {}
29  virtual ~TimeException() throw() {}
30 };
31 
32 struct tm;
33 # ifdef WIN32
34 typedef struct _FILETIME FILETIME;
35 # endif
36 
37 namespace Gaudi {
38 
39  class Time;
40  class TimeSpan;
41 
58  friend class Time;
59  public:
61 
62  TimeSpan (void);
63  TimeSpan (Time t);
64  TimeSpan (ValueType nsecs);
65  TimeSpan (ValueType secs, int nsecs);
66  TimeSpan (int days, int hours, int mins, int secs, int nsecs);
67 
68  int days (void) const;
69  int hours (void) const;
70  int minutes (void) const;
71  ValueType seconds (void) const;
72 
73  int lastHours (void) const;
74  int lastMinutes (void) const;
75  int lastSeconds (void) const;
76  int lastNSeconds (void) const;
77 
78  TimeSpan & operator+= (const TimeSpan &x);
79  TimeSpan & operator-= (const TimeSpan &x);
80  TimeSpan & operator*= (const TimeSpan &n);
81  TimeSpan & operator/= (const TimeSpan &n);
82  TimeSpan & operator%= (const TimeSpan &n);
83 
84  ValueType ns (void) const;
85 
86  private:
87  ValueType m_nsecs; //< The span length.
88  };
89 
90 
214  class GAUDI_API Time {
215  friend class TimeSpan;
216  public:
218 
220  enum Months {
221  January = 0,
222  February = 1,
223  March = 2,
224  April = 3,
225  May = 4,
226  June = 5,
227  July = 6,
228  August = 7,
229  September = 8,
230  October = 9,
231  November = 10,
232  December = 11
233  };
234 
236  static const int SECS_PER_DAY = 86400;
237 
239  static const int SECS_PER_HOUR = 3600;
240 
242  static const ValueType SEC_NSECS = 1000000000;
243 
244  Time (void);
245  Time (TimeSpan ts);
246  Time (ValueType nsecs);
247  Time (ValueType secs, int nsecs);
248  Time (int year, int month, int day, int hour, int min, int sec,
249  ValueType nsecs, bool local = true);
250  // implicit copy constructor
251  // implicit assignment operator
252  // implicit destructor
253 
255  static Time epoch (void);
257  static Time max (void);
259  static Time current (void);
260 # ifdef WIN32
261  static Time from (const FILETIME *systime);
262 # endif
263  static Time build (bool local, const tm &base, TimeSpan diff = 0);
264 
265  tm split (bool local, int *nsecpart = 0) const;
266  tm utc (int *nsecpart = 0) const;
267  tm local (int *nsecpart = 0) const;
268 
269  int year (bool local) const;
270  int month (bool local) const;
271  int day (bool local) const;
272  int hour (bool local) const;
273  int minute (bool local) const;
274  int second (bool local) const;
275  int nsecond (void) const;
276  int weekday (bool local) const;
277  bool isdst (bool local) const;
278 
279  ValueType utcoffset (int *daylight = 0) const;
280  const char * timezone (int *daylight = 0) const;
281 
282  Time & operator+= (const TimeSpan &x);
283  Time & operator-= (const TimeSpan &x);
284 
285  ValueType ns (void) const;
286 
287  std::string format (bool local, std::string spec = "%c") const;
288  std::string nanoformat (size_t minwidth = 1, size_t maxwidth = 9) const;
289 
290  static bool isLeap (int year);
291 
292  // Conversion helpers
293  static unsigned toDosDate (Time time);
294  static Time fromDosDate (unsigned dosDate);
295 
296  private:
297  ValueType m_nsecs; //< Time value as nsecs from #epoch().
298 
299  inline void TimeAssert(bool cond, const std::string &msg = "time assertion failed") const {
300  if (!cond) throw TimeException(msg);
301  }
302 
303  };
304 
305 }
306 
307 #include "GaudiKernel/Time.icpp"
308 
309 #endif // GAUDIKERNEL_TIME_H
longlong ValueType
Definition: Time.h:217
Define general base for Gaudi exception.
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133
longlong ValueType
Definition: Time.h:60
virtual ~TimeException()
Destructor needed to match the signature of GaudiException::~GaudiException().
Definition: Time.h:29
ValueType m_nsecs
Definition: Time.h:87
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:299
Months
Symbolic names for months.
Definition: Time.h:220
Based on seal::Time.
Definition: Time.h:214
TimeException(const std::string &Message="unspecified exception", const std::string &Tag="*Gaudi::Time*", const StatusCode &Code=StatusCode::FAILURE)
Definition: Time.h:24
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Exception thrown by Gaudi::Time.
Definition: Time.h:21
#define min(a, b)
ValueType m_nsecs
Definition: Time.h:297
The Message class.
Definition: Message.h:15
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
#define GAUDI_API
Definition: Kernel.h:108
Based on seal::TimeSpan.
Definition: Time.h:57