13 using namespace Gaudi;
21 # define NOGDICAPMASKS 42 # include <sys/time.h> 63 # define SECS_1601_TO_1970 ( ( 369 * 365 + 89 ) * 86400ui64 ) 67 static time_t timegm(
struct tm* t ) {
71 gmtime_s( &gmt, &t1 );
72 time_t t2 =
mktime( &gmt );
73 return t1 + ( t1 - t2 );
82 memset( &val, 0,
sizeof( val ) );
97 Time Time::from(
const FILETIME* systime ) {
102 t = ( t - SECS_1601_TO_1970 * (
SEC_NSECS / 100 ) ) * 100;
112 GetSystemTimeAsFileTime( &ftime );
113 return from( &ftime );
116 if ( gettimeofday( &tv,
nullptr ) != 0 ) {
119 tag <<
"errno=" << errno;
120 if ( strerror_r( errno, buf, 256 ) == 0 ) {
123 msg <<
"Unknown error retrieving current time";
127 return Time( tv.tv_sec, tv.tv_usec * 1000 );
134 return Time(
local ? mktime( &tmp ) : timegm( &tmp ), 0 ) + diff;
148 localtime_r( &val, &
retval );
150 gmtime_r( &val, &
retval );
208 tm localtm =
local();
209 n = localtm.tm_gmtoff;
210 if ( daylight ) *daylight = localtm.tm_isdst;
215 localtime_s( &localtm, &utctime );
216 int savedaylight = localtm.tm_isdst;
218 gmtime_s( &gmt, &utctime );
220 gmt.tm_isdst = savedaylight;
221 n = utctime - mktime( &gmt );
223 if ( daylight ) *daylight = savedaylight;
231 # pragma warning( push ) 232 # pragma warning( disable : 4996 ) 239 tm localtm =
local();
240 if ( daylight ) *daylight = localtm.tm_isdst;
242 return tzname[localtm.tm_isdst > 0 ? 1 : 0];
245 # pragma warning( pop ) 256 std::string::size_type length = 0;
259 std::string::size_type pos = spec.
find(
"%f" );
260 if ( std::string::npos != pos ) {
264 while ( std::string::npos != pos ) {
265 if ( pos != 0 && spec[pos - 1] !=
'%' ) { spec.
replace( pos, 2,
ms ); }
266 pos = spec.
find(
"%f", pos + 1 );
269 const int MIN_BUF_SIZE = 128;
272 result.
resize( std::max<std::string::size_type>(
273 result.
size() * 2, std::max<std::string::size_type>( spec.
size() * 2, MIN_BUF_SIZE ) ),
275 length = ::strftime( &result[0], result.
size(), spec.
c_str(), &
time );
293 TimeAssert( ( minwidth >= 1 ) && ( minwidth <= maxwidth ) && ( maxwidth <= 9 ),
294 "nanoformat options do not satisfy: 1 <= minwidth <= maxwidth <= 9" );
317 struct tm localtm =
time.local();
319 unsigned mday = localtm.tm_mday;
320 unsigned mon = localtm.tm_mon + 1;
321 unsigned year = ( localtm.tm_year > 80 ? localtm.tm_year - 80 : 0 );
322 unsigned sec = localtm.tm_sec / 2;
323 unsigned min = localtm.tm_min;
324 unsigned hour = localtm.tm_hour;
325 return ( mday << 16 | mon << 21 |
year << 25 | sec |
min << 5 |
hour << 11 );
335 memset( &localtm, 0,
sizeof( localtm ) );
336 localtm.tm_mday = ( dosDate >> 16 ) & 0x1f;
337 localtm.tm_mon = ( ( dosDate >> 21 ) & 0xf ) - 1;
338 localtm.tm_year = ( ( dosDate >> 25 ) & 0x7f ) + 80;
339 localtm.tm_hour = ( dosDate >> 11 ) & 0x1f;
340 localtm.tm_min = ( dosDate >> 5 ) & 0x3f;
341 localtm.tm_sec = ( dosDate & 0x1f ) * 2;
342 localtm.tm_isdst = -1;
344 return Time( mktime( &localtm ), 0 );
int year(bool local) const
Get the year.
Time()=default
Initialize an empty (zero) time value.
static Time build(bool local, const tm &base, TimeSpan diff=0)
Construct a time from local time base and a delta diff.
Define general base for Gaudi exception.
int day(bool local) const
Get the day of month, numbered [1,31].
static unsigned toDosDate(Time time)
Convert the Time t into a MS-DOS date format.
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 ti...
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
static Time current()
Returns the current time.
int hour(bool local) const
Get the hour, numbered [0, 23].
static const ValueType SEC_NSECS
Nanoseconds in one second.
const char * timezone(int *daylight=0) const
Return the local timezone name that applies at this time value.
int second(bool local) const
Get the seconds, numbered [0,61] (allowing one or two leap seconds, years with leap seconds can have ...
int nsecond() const
Get the nanoseconds.
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...
static Time fromDosDate(unsigned dosDate)
Convert the MS-DOS date dosDate into a Time.
int month(bool local) const
Get the month, numbered [0,11].
T find_last_not_of(T... args)
int weekday(bool local) const
Get the day of week, numbered [0,6] and starting from Sunday.
bool isdst(bool local) const
Check whether daylight savings is in effect.
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
constexpr static const auto FAILURE
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time.
int minute(bool local) const
Get the minute, numbered [0, 59].
Header file for std:chrono::duration-based Counters.
tm utc(int *nsecpart=0) const
Break up the time to the standard library representation, keeping it in UTC.
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
std::string nanoformat(size_t minwidth=1, size_t maxwidth=9) const
Format the nanosecond fractional part of the time as a string.