| The Gaudi Framework v27r1

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

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Gaudi::Time Class Reference

Based on seal::Time. More...

`#include <GaudiKernel/Time.h>`

Collaboration diagram for Gaudi::Time:
[legend]

## Public Types
enum | Months { January = 0, February = 1, March = 2, April = 3, May = 4, June = 5, July = 6, August = 7, September = 8, October = 9, November = 10, December = 11 }
| Symbolic names for months. More...
typedef longlong | ValueType

## Public Member Functions
| Time (void)
| Initialize an empty (zero) time value. More...
| Time (TimeSpan ts)
| Initialize time to ts nanoseconds since 00:00:00 on January 1, 1970 in UTC. More...
| Time (ValueType nsecs)
| Initialize time to nsecs nanoseconds since 00:00:00 on January 1, 1970 in UTC. More...
| Time (ValueType secs, int nsecs)
| Initialize time to secs (seconds) and nsecs (nanoseconds) summed since 00:00:00 on January 1, 1970 in UTC. More...
| Time (int year, int month, int day, int hour, int min, int sec, ValueType nsecs, bool local=true)
tm | split (bool local, int *nsecpart=0) const
| Break up the time to the standard representation, either in UTC (if local is `false`) or local time (if local is `true`). More...
tm | utc (int *nsecpart=0) const
| Break up the time to the standard library representation, keeping it in UTC. More...
tm | local (int *nsecpart=0) const
| Break up the time to the standard library representation, converting it first to local time. More...
int | year (bool local) const
| Get the year. More...
int | month (bool local) const
| Get the month, numbered [0,11]. More...
int | day (bool local) const
| Get the day of month, numbered [1,31]. More...
int | hour (bool local) const
| Get the hour, numbered [0, 23]. More...
int | minute (bool local) const
| Get the minute, numbered [0, 59]. More...
int | second (bool local) const
| Get the seconds, numbered [0,61] (allowing one or two leap seconds, years with leap seconds can have the time Dec 31, 23:59:60 (or :61).) More...
int | nsecond (void) const
| Get the nanoseconds. More...
int | weekday (bool local) const
| Get the day of week, numbered [0,6] and starting from Sunday. More...
bool | isdst (bool local) const
| Check whether daylight savings is in effect. More...
ValueType | utcoffset (int *daylight=0) const
| Return the number of nanoseconds that needs to be added to UTC to translate this time to the local time (= nanoseconds east of UTC). More...
const char * | timezone (int *daylight=0) const
| Return the local timezone name that applies at this time value. More...
Time & | operator+= (const TimeSpan &x)
| Add the specified amount to the time. More...
Time & | operator-= (const TimeSpan &x)
| Subtract the specified amount from the time. More...
ValueType | ns (void) const
| Return the time as nanoseconds since 00:00:00 on January 1, 1970 in UTC. More...
std::string | format (bool local, std::string spec="%c") const
| Format the time using `strftime`. More...
std::string | nanoformat (size_t minwidth=1, size_t maxwidth=9) const
| Format the nanosecond fractional part of the time as a string. More...

## Static Public Member Functions
static Time | epoch (void)
| Returns the minimum time. More...
static Time | max (void)
| Returns the maximum time. More...
static Time | current (void)
| Returns the current time. More...
static Time | build (bool local, const tm &base, TimeSpan diff=0)
| Construct a time from local time base and a delta diff. More...
static bool | isLeap (int year)
| Check if the year is a leap-year. More...
static unsigned | toDosDate (Time time)
| Convert the Time t into a MS-DOS date format. More...
static Time | fromDosDate (unsigned dosDate)
| Convert the MS-DOS date dosDate into a Time. More...

## Static Public Attributes
static const int | SECS_PER_DAY = 86400
| Seconds in 24 hours. More...
static const int | SECS_PER_HOUR = 3600
| Seconds in one hour hour. More...
static const ValueType | SEC_NSECS = 1000000000
| Nanoseconds in one second. More...

## Private Member Functions
void | TimeAssert (bool cond, const std::string &msg="time assertion failed") const

## Private Attributes
ValueType | m_nsecs

## Friends
class | TimeSpan

## Detailed Description

Based on seal::Time.

Calendar time in nanoseconds since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).

Time is represented internally as UTC time, but it can also be converted to the local time as necessary. Most methods take an argument flag `local` to indicate which time interpretation is desired by the client, and automatically perform the necessary adjustments. The client can also find out about the difference between UTC time and local time using the utcoffset() method, and the time zone name with timezone() method. Both allow the client to discover whether daylight savings is in effect.

The native representation of Time is not well suited for human handling of time. Time provides access in more convenient terms such as year(), month() and day(); more are available through conversion into a TimeSpan. Time can also be converted to and from ISO C standard `tm` structure. Note however that unlike C's `mktime()` which always assumes `tm` in local time, Time fully supports all conversions between local and universal time. Thus it is possible for example to build() a UTC time directly from a `tm`.

Time behaves as an integral type. Differences in time values are represented as a TimeSpan. Usual integral arithmetic works with both types. Output works in general as any other integral type, however since the ValueType can be a wide type, it may be poorly supported by the `iostream`; if so, including the `LongLong.h` header will help. Note that the output value will usually be very large as Time is represented in nanoseconds, not seconds! When constructing Time values in seconds, such as when reading in, do remember to use the two-argument constructor taking seconds and nanoseconds instead of the default single-argument one.

Time can be formatted into a string using the format() method, which uses the versatile `strftime()` function. Since the latter works on seconds at best (through a struct `tm`), the subsecond part cannot be formatted; the nanoformat() method is provided to overcome this limitation. To combine format() and nanoformat() output use a suitable #StringFormat pattern.

Time is linked to the system's concept of calendar time and is therefore may not be linear nor monotonic. System time can jump arbitrarily in either direction as real time clock is corrected or the system is suspended. The local time may also jump due to daylight savings. The process' ability to sample system time can be limited for reasons such as getting swapped out. #TimeInfo provides an alternative time measurement facility not linked to calendar and guaranteed to grow monotonically – though not always linearly. Note that few systems actually provide wall-clock time in nanosecond resolution. Not all system provide an interface to get time at that resolution, let alone track it so precisely.

Because of the time warp issues, scheduling events using Time is not straightforward. Application code should understand whether it is dealing with concrete or abstract calendar calculations, and how the events it schedules are linked to wall clock time.

For calculations on concrete calendar as perceived by people use local() after plain Time and TimeSpan integer arithmetic. The method accounts for timezone and daylight savings definitions. To schedule events use build() to derive times from local() time to get values comparable to the system time returned by current(). The applications should know whether events are scheduled in UTC or local time—"meeting at 9:00 on Wednesday morning" when the device switches timezones may be known to be at 9:00 in the new timezone (= locked to local time), or in the timezone where the event was created (= locked to UTC). The build() and split() methods allow either format to be used, the application just needs to know which one to use. It is also easy to convert between the two using utcoffset().

For calculations using an abstract calendar, without timezone or daylight savings, use Time in its native UTC representation and integer arithmetic with Time and TimeSpan. Do note however that "T + 24 hours" may not be the same hour the next day in the local calendar time – timezone changes and daylight savings make a difference. This may require the application to accept as user input exception rules to its usual calendar calculations.

To schedule events, one should choose between three choices: UTC time, local time, or delta time. For the first two cases system time should be polled regularly to see if any of the recorded events have expired. It is not a good idea to sleep until the next scheduled event, as the system time may jump during the nap; instead sleep small increments, recheck the current time after each nap and trigger the events that have expired. A policy must be applied when the system time warps; this can happen both forwards and backwards with both local and UTC time (daylight savings or timezone changes for mobile devices are common local time change reasons, but the system time can be updated for any reason, e.g. when the real time clock is wrong, or if the system is suspended for a long time). Some events should be executed only once in case of time warps backwards. If the time jumps forwards, several events may need to be dealt with in one go. In either case the application should guard against major time changes: long system suspends, moving mobile devices and major time updates may result in a large number of "missed" events. One possibility is to provide a user-configurable "excessive time drift limit" (e.g. N hours): if time changes by more than that, missed events are not triggered.

For the final case of using delta times, sort upcoming events by their deltas from the previous event—not by the time they are anticipated to occur. Capture current time before and after the sleep and pull events off the queue based on the difference (the sleep time may exceed the requested time). Either guard against long time warps like suspends or schedule timer events cautiously. Using #TimeInfo as schedule base solves such issues simply. To cope with backward system time jumps when using Time as schedule base, assume that sleeps always last at least the requested time; if the time delta over the nap is less than the requested, assume time warp (this is not foolproof against interrupted system calls but works for many event scheduling situations).

See also
  #TimeInfo for monotonic time not related to the calendar. (Documentation taken from original SEAL class)

Author
  Marco Clemencic

Date
  2005-12-15

Definition at line 213 of file Time.h.

## Member Typedef Documentation

typedef longlong Gaudi::Time::ValueType

Definition at line 216 of file Time.h.

## Member Enumeration Documentation

enum Gaudi::Time::Months

Symbolic names for months.

Enumerator
January |
February |
March |
April |
May |
June |
July |
August |
September |
October |
November |
December |

Definition at line 219 of file Time.h.

219 {
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 };
Gaudi::Time::May
Definition: Time.h:224
Gaudi::Time::February
Definition: Time.h:221
Gaudi::Time::October
Definition: Time.h:229
Gaudi::Time::September
Definition: Time.h:228
Gaudi::Time::April
Definition: Time.h:223
Gaudi::Time::June
Definition: Time.h:225
Gaudi::Time::December
Definition: Time.h:231
Gaudi::Time::November
Definition: Time.h:230
Gaudi::Time::July
Definition: Time.h:226
Gaudi::Time::March
Definition: Time.h:222
Gaudi::Time::January
Definition: Time.h:220
Gaudi::Time::August
Definition: Time.h:227

## Constructor & Destructor Documentation

Gaudi::Time::Time | ( | void |  | ) |
| inline

Initialize an empty (zero) time value.

Definition at line 9 of file Time.icpp.

9 : m_nsecs(0) {}
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

Gaudi::Time::Time | ( | TimeSpan | ts | ) |
| inline

Initialize time to ts nanoseconds since 00:00:00 on January 1, 1970 in UTC.

Definition at line 19 of file Time.icpp.

19 : m_nsecs(ts.m_nsecs) {
20 TimeAssert( m_nsecs >= 0, "cannot create a negative time");
21 }
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:298
compareRootHistos.ts
tuple ts
Definition: compareRootHistos.py:342
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

Gaudi::Time::Time | ( | ValueType | nsecs | ) |
| inline

Initialize time to nsecs nanoseconds since 00:00:00 on January 1, 1970 in UTC.

Definition at line 13 of file Time.icpp.

13 : m_nsecs(nsecs) {
14 TimeAssert( m_nsecs >= 0, "cannot create a negative time");
15 }
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:298
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

Gaudi::Time::Time | ( | ValueType | secs,
|  | int | nsecs
| ) |  |
| inline

Initialize time to secs (seconds) and nsecs (nanoseconds) summed since 00:00:00 on January 1, 1970 in UTC.

Definition at line 25 of file Time.icpp.

26 : m_nsecs(secs * Time::SEC_NSECS + nsecs) {
27 TimeAssert( m_nsecs >= 0, "cannot create a negative time");
28 }
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:298
Gaudi::Time::SEC_NSECS
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:241
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

Time::Time | ( | int | year,
|  | int | month,
|  | int | day,
|  | int | hour,
|  | int | min,
|  | int | sec,
|  | ValueType | nsecs,
|  | bool | local = `true`
| ) |  |

Definition at line 80 of file Time.cpp.

83 {
84 tm val;
85 memset (&val, 0, sizeof (val));
86 val.tm_sec = sec;
87 val.tm_min = min;
88 val.tm_hour = hour;
89 val.tm_mday = day;
90 val.tm_mon = month;
91 val.tm_year = year > 1900 ? year - 1900 : year;
92 val.tm_isdst = -1; // FIXME?
93
94 m_nsecs = build (local, val, nsecs).m_nsecs;
95 }
Gaudi::Time::hour
int hour(bool local) const
Get the hour, numbered [0, 23].
Definition: Time.cpp:190
Gaudi::Time::build
static Time build(bool local, const tm &base, TimeSpan diff=0)
Construct a time from local time base and a delta diff.
Definition: Time.cpp:136
Gaudi::Time::day
int day(bool local) const
Get the day of month, numbered [1,31].
Definition: Time.cpp:185
Gaudi::Time::month
int month(bool local) const
Get the month, numbered [0,11].
Definition: Time.cpp:180
std::memset
T memset(T...args)
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170
std::min
T min(T...args)
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296
Gaudi::Time::year
int year(bool local) const
Get the year.
Definition: Time.cpp:175

## Member Function Documentation

Time Time::build | ( | bool | local,
|  | const tm & | base,
|  | TimeSpan | diff = `0`
| ) |  |
| static

Construct a time from local time base and a delta diff.

Definition at line 136 of file Time.cpp.

136 {
137 tm tmp (base);
138 return Time (local ? mktime(&tmp) : timegm(&tmp), 0) + diff;
139 }
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170
std::mktime
T mktime(T...args)
Gaudi::Time::Time
Time(void)
Initialize an empty (zero) time value.
Definition: Time.icpp:9

Time Time::current | ( | void |  | ) |
| static

Returns the current time.

Return the current system time.

Definition at line 113 of file Time.cpp.

113 {
114 #ifdef WIN32
115 FILETIME ftime;
116 GetSystemTimeAsFileTime (&ftime);
117 return from (&ftime);
118 #else
119 timeval tv;
120 if (gettimeofday (&tv, nullptr) != 0) {
121 char buf[256];
122 std::ostringstream tag,msg;
123 tag << "errno=" << errno;
124 if( strerror_r(errno, buf, 256) == nullptr ) {
125 msg << buf;
126 } else {
127 msg << "Unknown error retrieving current time";
128 }
129 throw GaudiException(msg.str(),tag.str(),StatusCode::FAILURE);
130 }
131 return Time (tv.tv_sec, tv.tv_usec * 1000);
132 #endif
133 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
GaudiMP.FdsRegistry.msg
tuple msg
Definition: FdsRegistry.py:8
StatusCode::FAILURE
Definition: StatusCode.h:29
std::ostringstream
STL class.
std::ostringstream::str
T str(T...args)
Gaudi::Time::Time
Time(void)
Initialize an empty (zero) time value.
Definition: Time.icpp:9

int Time::day | ( | bool | local | ) | const

Get the day of month, numbered [1,31].

Definition at line 185 of file Time.cpp.

185 {
186 return split (local).tm_mday;
187 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

Time Gaudi::Time::epoch | ( | void |  | ) |
| inline static

Returns the minimum time.

Return the time for the epoch (= zero time).

Definition at line 53 of file Time.icpp.

53 {
54 return 0LL;
55 }

std::string Time::format | ( | bool | local,
|  | std::string | spec = `"%c"`
| ) |  | const

Format the time using `strftime`.

The additional conversion specifier f can be used to display milliseconds (extension for compatibility with MessageSvc time format).

Fix-Me:
  : This doesn't account for nsecs part!

Definition at line 279 of file Time.cpp.

279 {
281 std::string result;
282 tm time = split (local);
283 std::string::size_type length = 0;
284
285 // handle the special case of "%f"
286 std::string::size_type pos = spec.find("%f");
287 if (std::string::npos != pos) {
288 // Get the milliseconds string
289 std::string ms = nanoformat(3,3);
290 // Replace all the occurrences of '%f' (if not preceded by '%')
291 while (std::string::npos != pos) {
292 if (pos != 0 && spec[pos-1] != '%') {
293 spec.replace(pos, 2, ms);
294 }
295 pos = spec.find("%f", pos + 1); // search for the next occurrence
296 }
297 }
298 const int MIN_BUF_SIZE = 128;
299 do
300 {
301 // Guess how much we'll expand. If we go wrong, we'll expand again. (with a minimum)
302 result.resize(std::max<std::string::size_type>(result.size()*2,
303 std::max<std::string::size_type>(spec.size()*2, MIN_BUF_SIZE))
304 , 0);
305 length = ::strftime (&result[0], result.size(), spec.c_str(), &time);
306 } while (! length);
307
308 result.resize (length);
309 return result;
310 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
plotSpeedupsPyRoot.time
tuple time
Definition: plotSpeedupsPyRoot.py:146
std::string::resize
T resize(T...args)
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170
std::string
STL class.
std::string::replace
T replace(T...args)
Gaudi::Time::nanoformat
std::string nanoformat(size_t minwidth=1, size_t maxwidth=9) const
Format the nanosecond fractional part of the time as a string.
Definition: Time.cpp:322
std::string::find
T find(T...args)
std::string::size
T size(T...args)
std::string::c_str
T c_str(T...args)
AthenaScenario.ms
tuple ms
Definition: AthenaScenario.py:72

Time Time::fromDosDate | ( | unsigned | dosDate | ) |
| static

Convert the MS-DOS date dosDate into a Time.

Definition at line 360 of file Time.cpp.

360 {
361 // DOS times are generally local; treat it as UTC. This avoids
362 // any round-trip conversion and leaves only a presentation as an
363 // issue. Since not much can be known about the origin of the DOS
364 // times, it's generally best to present them as such (= in UTC).
365 struct tm localtm;
366 memset (&localtm, 0, sizeof (localtm));
367 localtm.tm_mday = (dosDate >> 16) & 0x1f;
368 localtm.tm_mon = ((dosDate >> 21) & 0xf) - 1;
369 localtm.tm_year = ((dosDate >> 25) & 0x7f) + 80;
370 localtm.tm_hour = (dosDate >> 11) & 0x1f;
371 localtm.tm_min = (dosDate >> 5) & 0x3f;
372 localtm.tm_sec = (dosDate & 0x1f) * 2;
373 localtm.tm_isdst = -1;
374
375 return Time (mktime (&localtm), 0);
376 }
std::memset
T memset(T...args)
Gaudi::Time::Time
Time(void)
Initialize an empty (zero) time value.
Definition: Time.icpp:9

int Time::hour | ( | bool | local | ) | const

Get the hour, numbered [0, 23].

Definition at line 190 of file Time.cpp.

190 {
191 return split (local).tm_hour;
192 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

bool Time::isdst | ( | bool | local | ) | const

Check whether daylight savings is in effect.

This really only makes sense if local is true since daylight savings is never in effect for UTC time.

Definition at line 221 of file Time.cpp.

221 {
222 return split (local).tm_isdst > 0;
223 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

bool Gaudi::Time::isLeap | ( | int | year | ) |
| inline static

Check if the year is a leap-year.

Definition at line 63 of file Time.icpp.

63 {
64 return ((year % 4) == 0
65 && ((year % 100) != 0
66 || (year % 400) == 0));
67 }
Gaudi::Time::year
int year(bool local) const
Get the year.
Definition: Time.cpp:175

tm Time::local | ( | int * | nsecpart = `0` | ) | const

Break up the time to the standard library representation, converting it first to local time.

If nsecpart is non-null, it is set to the nanosecond part that cannot be stored into `tm`.

Definition at line 170 of file Time.cpp.

170 {
171 return split (true, nsecpart);
172 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145

Time Gaudi::Time::max | ( | void |  | ) |
| inline static

Returns the maximum time.

Return the maximum time.

Definition at line 58 of file Time.icpp.

58 {
59 return 0x7fffffffffffffffLL;
60 }

int Time::minute | ( | bool | local | ) | const

Get the minute, numbered [0, 59].

Definition at line 195 of file Time.cpp.

195 {
196 return split (local).tm_min;
197 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

int Time::month | ( | bool | local | ) | const

Get the month, numbered [0,11].

Definition at line 180 of file Time.cpp.

180 {
181 return split (local).tm_mon;
182 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

std::string Time::nanoformat | ( | size_t | minwidth = `1`,
|  | size_t | maxwidth = `9`
| ) |  | const

Format the nanosecond fractional part of the time as a string.

The arguments control the representation of the resulting value. The nanosecond part is printed as fixed nine-character-wide number and then excess zeroes are stripped off at the right end. Use minwidth to force a specific number number of them to be left intact: the resulting number will have at least that many digits. Use maxwidth to truncate the value: the resulting number will have at most that many digits. Both minwidth and maxwidth must be between one and nine inclusive and minwidth must be less or equal to maxwidth.

Definition at line 322 of file Time.cpp.

322 {
323 TimeAssert( (minwidth >= 1) && (minwidth <= maxwidth) && (maxwidth <= 9),
324 "nanoformat options do not satisfy: 1 <= minwidth <= maxwidth <= 9");
325
326 // Calculate the nanosecond fraction. This will be < 1000000000.
327 int value = (int)(m_nsecs % SEC_NSECS);
328
329 std::ostringstream buf;
330 buf.fill('0');
331 buf.width(9);
332 buf << value;
333 std::string out = buf.str();
334 // Find the last non-0 char before maxwidth, but after minwidth
335 // (Note: -1 and +1 are to account for difference between position and size.
336 // moreover, npos + 1 == 0, so it is correct to say that 'not found' means size of 0)
337 size_t len = out.find_last_not_of('0', maxwidth - 1) + 1;
338 // Truncate the output string to at least minwidth chars
339 out.resize(std::max(len, minwidth));
340 return out;
341 }
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:298
std::string::resize
T resize(T...args)
Gaudi::Time::SEC_NSECS
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:241
std::string
STL class.
std::ostringstream
STL class.
std::ostringstream::width
T width(T...args)
std::ostringstream::str
T str(T...args)
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
std::max
T max(T...args)
std::string::find_last_not_of
T find_last_not_of(T...args)
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296
std::ostringstream::fill
T fill(T...args)

Time::ValueType Gaudi::Time::ns | ( | void |  | ) | const
| inline

Return the time as nanoseconds since 00:00:00 on January 1, 1970 in UTC.

Definition at line 32 of file Time.icpp.

32 {
33 return m_nsecs;
34 }
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

int Time::nsecond | ( | void |  | ) | const

Get the nanoseconds.

There is no `local` argument since time zone and daylight savings never affects the value at the subsecond granularity.

Definition at line 209 of file Time.cpp.

209 {
210 return (int)(m_nsecs % SEC_NSECS);
211 }
Gaudi::Time::SEC_NSECS
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:241
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

Time & Gaudi::Time::operator+= | ( | const TimeSpan & | x | ) |
| inline

Add the specified amount to the time.

Note that Time is always expressed in UTC.

Definition at line 38 of file Time.icpp.

38 {
39 TimeAssert( m_nsecs >= -x.m_nsecs, "time operation lead to negative time");
40 m_nsecs += x.m_nsecs;
41 return *this;
42 }
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:298
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

Time & Gaudi::Time::operator-= | ( | const TimeSpan & | x | ) |
| inline

Subtract the specified amount from the time.

Note that Time is always expressed in UTC.

Definition at line 46 of file Time.icpp.

46 {
47 TimeAssert( m_nsecs >= x.m_nsecs, "time operation lead to negative time");
48 m_nsecs -= x.m_nsecs;
49 return *this;
50 }
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:298
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

int Time::second | ( | bool | local | ) | const

Get the seconds, numbered [0,61] (allowing one or two leap seconds, years with leap seconds can have the time Dec 31, 23:59:60 (or :61).)

Definition at line 202 of file Time.cpp.

202 {
203 return split (local).tm_sec;
204 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

tm Time::split | ( | bool | local,
|  | int * | nsecpart = `0`
| ) |  | const

Break up the time to the standard representation, either in UTC (if local is `false`) or local time (if local is `true`).

If nsecpart is non-null, it is set to the nanosecond part that cannot be stored into `tm`.

Definition at line 145 of file Time.cpp.

145 {
146 if (nsecpart)
147 *nsecpart = (int)(m_nsecs % SEC_NSECS);
148
149 time_t val = (time_t)(m_nsecs / SEC_NSECS);
150
151 tm retval;
152 if (local)
153 localtime_r(&val, &retval);
154 else
155 gmtime_r(&val, &retval);
156
157 return retval;
158 }
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170
Gaudi::Time::SEC_NSECS
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:241
compareRootHistos.retval
tuple retval
Definition: compareRootHistos.py:351
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

void Gaudi::Time::TimeAssert | ( | bool | cond,
|  | const std::string & | msg = `"time assertion failed"`
| ) |  | const
| inline private

Definition at line 298 of file Time.h.

298 {
299 if (!cond) throw TimeException(msg);
300 }
TimeException
Exception thrown by Gaudi::Time.
Definition: Time.h:20

const char * Time::timezone | ( | int * | daylight = `0` | ) | const

Return the local timezone name that applies at this time value.

On some platforms returns the most recent timezone name (dst or non-dst one depending on the time value), not the one that applies at the time value.

Definition at line 265 of file Time.cpp.

265 {
266 tm localtm = local ();
267 if (daylight) *daylight = localtm.tm_isdst;
268 // extern "C" { extern char *tzname [2]; }
269 return tzname [localtm.tm_isdst > 0 ? 1 : 0];
270 }
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

unsigned Time::toDosDate | ( | Time | time | ) |
| static

Convert the Time t into a MS-DOS date format.

Definition at line 345 of file Time.cpp.

345 {
346 // Use local time since DOS does too.
347 struct tm localtm = time.local ();
348
349 unsigned mday = localtm.tm_mday;
350 unsigned mon = localtm.tm_mon + 1;
351 unsigned year = (localtm.tm_year > 80 ? localtm.tm_year - 80 : 0);
352 unsigned sec = localtm.tm_sec / 2;
353 unsigned min = localtm.tm_min;
354 unsigned hour = localtm.tm_hour;
355 return (mday << 16 | mon << 21 | year << 25
356 | sec | min << 5 | hour << 11);
357 }
Gaudi::Time::hour
int hour(bool local) const
Get the hour, numbered [0, 23].
Definition: Time.cpp:190
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170
std::min
T min(T...args)
Gaudi::Time::year
int year(bool local) const
Get the year.
Definition: Time.cpp:175

tm Time::utc | ( | int * | nsecpart = `0` | ) | const

Break up the time to the standard library representation, keeping it in UTC.

If nsecpart is non-null, it is set to the nanosecond part that cannot be stored into `tm`.

Definition at line 163 of file Time.cpp.

163 {
164 return split (false, nsecpart);
165 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145

Time::ValueType Time::utcoffset | ( | int * | daylight = `0` | ) | const

Return the number of nanoseconds that needs to be added to UTC to translate this time to the local time (= nanoseconds east of UTC).

This accounts for the time zone and daylight savings settings of the local time as of the current value. If daylight is non-null, it is set to indicate daylight savings status (that is, tm.tm_isdst for the effective local time).

Definition at line 231 of file Time.cpp.

231 {
232 ValueType n = 0;
233
234 #ifndef WIN32
235 tm localtm = local ();
236 n = localtm.tm_gmtoff;
237 if (daylight) *daylight = localtm.tm_isdst;
238 #else
239 // Adapted from WINE.
240 time_t utctime = (time_t)(m_nsecs / SEC_NSECS);
241 tm localtm;
242 localtime_s(&localtm, &utctime);
243 int savedaylight = localtm.tm_isdst;
244 tm gmt;
245 gmtime_s(&gmt, &utctime);
246
247 gmt.tm_isdst = savedaylight;
248 n = utctime - mktime (&gmt);
249
250 if (daylight) *daylight = savedaylight;
251 #endif
252 return n * SEC_NSECS;
253 }
Gaudi::Time::ValueType
longlong ValueType
Definition: Time.h:216
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170
Gaudi::Time::SEC_NSECS
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:241
std::mktime
T mktime(T...args)
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296

int Time::weekday | ( | bool | local | ) | const

Get the day of week, numbered [0,6] and starting from Sunday.

Definition at line 214 of file Time.cpp.

214 {
215 return split (local).tm_wday;
216 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

int Time::year | ( | bool | local | ) | const

Get the year.

Definition at line 175 of file Time.cpp.

175 {
176 return split (local).tm_year + 1900;
177 }
Gaudi::Time::split
tm split(bool local, int *nsecpart=0) const
Break up the time to the standard representation, either in UTC (if local is false) or local time (if...
Definition: Time.cpp:145
Gaudi::Time::local
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time...
Definition: Time.cpp:170

## Friends And Related Function Documentation

friend class TimeSpan
| friend

Definition at line 214 of file Time.h.

## Member Data Documentation

ValueType Gaudi::Time::m_nsecs
| private

Definition at line 296 of file Time.h.

const ValueType Gaudi::Time::SEC_NSECS = 1000000000
| static

Nanoseconds in one second.

Definition at line 241 of file Time.h.

const int Gaudi::Time::SECS_PER_DAY = 86400
| static

Seconds in 24 hours.

Definition at line 235 of file Time.h.

const int Gaudi::Time::SECS_PER_HOUR = 3600
| static

Seconds in one hour hour.

Definition at line 238 of file Time.h.

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

- GaudiKernel/GaudiKernel/Time.h
- GaudiKernel/GaudiKernel/Time.icpp
- GaudiKernel/src/Lib/Time.cpp