| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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"
8 #include "GaudiKernel/StreamBuffer.h"
9 #include "GaudiKernel/GaudiException.h"
10
21 class GAUDI_API TimeException: public GaudiException {
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
57 class GAUDI_API TimeSpan {
58 friend class Time;
59 public:
60 typedef longlong ValueType;
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:
217 typedef longlong ValueType;
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