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