Go to the documentation of this file.
23 using namespace Gaudi;
31 # define NOGDICAPMASKS
52 # include <sys/time.h>
73 # define SECS_1601_TO_1970 ( ( 369 * 365 + 89 ) * 86400ui64 )
77 static time_t timegm(
struct tm*
t ) {
81 gmtime_s( &gmt, &
t1 );
92 memset( &val, 0,
sizeof( val ) );
107 Time Time::from(
const FILETIME* systime ) {
112 t = (
t - SECS_1601_TO_1970 * (
SEC_NSECS / 100 ) ) * 100;
122 GetSystemTimeAsFileTime( &ftime );
123 return from( &ftime );
126 if ( gettimeofday( &tv,
nullptr ) != 0 ) {
129 tag <<
"errno=" << errno;
130 if ( strerror_r( errno, buf, 256 ) == 0 ) {
133 msg <<
"Unknown error retrieving current time";
137 return Time( tv.tv_sec, tv.tv_usec * 1000 );
144 return Time(
local ? mktime( &tmp ) : timegm( &tmp ), 0 ) + diff;
158 localtime_r( &val, &
retval );
160 gmtime_r( &val, &
retval );
218 tm localtm =
local();
219 n = localtm.tm_gmtoff;
220 if ( daylight ) *daylight = localtm.tm_isdst;
225 localtime_s( &localtm, &utctime );
226 int savedaylight = localtm.tm_isdst;
228 gmtime_s( &gmt, &utctime );
230 gmt.tm_isdst = savedaylight;
231 n = utctime - mktime( &gmt );
233 if ( daylight ) *daylight = savedaylight;
241 # pragma warning( push )
242 # pragma warning( disable : 4996 )
249 tm localtm =
local();
250 if ( daylight ) *daylight = localtm.tm_isdst;
252 return tzname[localtm.tm_isdst > 0 ? 1 : 0];
255 # pragma warning( pop )
266 std::string::size_type length = 0;
269 std::string::size_type pos = spec.
find(
"%f" );
270 if ( std::string::npos != pos ) {
274 while ( std::string::npos != pos ) {
275 if ( pos != 0 && spec[pos - 1] !=
'%' ) { spec.
replace( pos, 2,
ms ); }
276 pos = spec.
find(
"%f", pos + 1 );
279 const int MIN_BUF_SIZE = 128;
282 result.
resize( std::max<std::string::size_type>(
283 result.
size() * 2, std::max<std::string::size_type>( spec.
size() * 2, MIN_BUF_SIZE ) ),
285 length = ::strftime( &result[0], result.
size(), spec.
c_str(), &
time );
303 TimeAssert( ( minwidth >= 1 ) && ( minwidth <= maxwidth ) && ( maxwidth <= 9 ),
304 "nanoformat options do not satisfy: 1 <= minwidth <= maxwidth <= 9" );
310 (void)buf.
fill(
'0' );
317 size_t len =
out.find_last_not_of(
'0', maxwidth - 1 ) + 1;
327 struct tm localtm =
time.local();
329 unsigned mday = localtm.tm_mday;
330 unsigned mon = localtm.tm_mon + 1;
331 unsigned year = ( localtm.tm_year > 80 ? localtm.tm_year - 80 : 0 );
332 unsigned sec = localtm.tm_sec / 2;
333 unsigned min = localtm.tm_min;
334 unsigned hour = localtm.tm_hour;
335 return ( mday << 16 | mon << 21 |
year << 25 | sec | min << 5 |
hour << 11 );
345 memset( &localtm, 0,
sizeof( localtm ) );
346 localtm.tm_mday = ( dosDate >> 16 ) & 0x1f;
347 localtm.tm_mon = ( ( dosDate >> 21 ) & 0xf ) - 1;
348 localtm.tm_year = ( ( dosDate >> 25 ) & 0x7f ) + 80;
349 localtm.tm_hour = ( dosDate >> 11 ) & 0x1f;
350 localtm.tm_min = ( dosDate >> 5 ) & 0x3f;
351 localtm.tm_sec = ( dosDate & 0x1f ) * 2;
352 localtm.tm_isdst = -1;
354 return Time( mktime( &localtm ), 0 );
bool isdst(bool local) const
Check whether daylight savings is in effect.
int year(bool local) const
Get the year.
int second(bool local) const
Get the seconds, numbered [0,61] (allowing one or two leap seconds, years with leap seconds can have ...
Time()=default
Initialize an empty (zero) time value.
std::string nanoformat(size_t minwidth=1, size_t maxwidth=9) const
Format the nanosecond fractional part of the time as a string.
const char * timezone(int *daylight=0) const
Return the local timezone name that applies at this time value.
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...
int minute(bool local) const
Get the minute, numbered [0, 59].
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
static unsigned toDosDate(Time time)
Convert the Time t into a MS-DOS date format.
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...
int hour(bool local) const
Get the hour, numbered [0, 23].
int weekday(bool local) const
Get the day of week, numbered [0,6] and starting from Sunday.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
static const ValueType SEC_NSECS
Nanoseconds in one second.
static Time current()
Returns the current time.
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time.
int month(bool local) const
Get the month, numbered [0,11].
void TimeAssert(bool cond, std::string_view msg="time assertion failed") const
TemplatedAlg< double, bool > t2
int nsecond() const
Get the nanoseconds.
int day(bool local) const
Get the day of month, numbered [1,31].
constexpr static const auto FAILURE
static Time fromDosDate(unsigned dosDate)
Convert the MS-DOS date dosDate into a Time.
tm utc(int *nsecpart=0) const
Break up the time to the standard library representation, keeping it in UTC.
static Time build(bool local, const tm &base, TimeSpan diff=0)
Construct a time from local time base and a delta diff.