28 memset( &val, 0,
sizeof( val ) );
43 if ( gettimeofday( &tv,
nullptr ) != 0 ) {
45 std::ostringstream tag, msg;
46 tag <<
"errno=" << errno;
47 if ( strerror_r( errno, buf, 256 ) == 0 ) {
50 msg <<
"Unknown error retrieving current time";
54 return Time( tv.tv_sec, tv.tv_usec * 1000 );
60 return Time(
local ? mktime( &tmp ) : timegm( &tmp ), 0 ) + diff;
74 localtime_r( &val, &retval );
76 gmtime_r( &val, &retval );
133 tm localtm =
local();
134 n = localtm.tm_gmtoff;
135 if ( daylight ) *daylight = localtm.tm_isdst;
145 tm localtm =
local();
146 if ( daylight ) *daylight = localtm.tm_isdst;
148 return tzname[localtm.tm_isdst > 0 ? 1 : 0];
159 std::string::size_type length = 0;
162 std::string::size_type pos = spec.find(
"%f" );
163 if ( std::string::npos != pos ) {
167 while ( std::string::npos != pos ) {
168 if ( pos != 0 && spec[pos - 1] !=
'%' ) { spec.replace( pos, 2, ms ); }
169 pos = spec.find(
"%f", pos + 1 );
172 const std::size_t MIN_BUF_SIZE = 128;
175 result.resize( std::max( result.size() * 2, std::max( spec.size() * 2, MIN_BUF_SIZE ) ), 0 );
176 length = ::strftime( &result[0], result.size(), spec.c_str(), &time );
179 result.resize( length );
194 TimeAssert( ( minwidth >= 1 ) && ( minwidth <= maxwidth ) && ( maxwidth <= 9 ),
195 "nanoformat options do not satisfy: 1 <= minwidth <= maxwidth <= 9" );
200 std::ostringstream buf;
201 (void)buf.fill(
'0' );
204 std::string out = buf.str();
208 size_t len = out.find_last_not_of(
'0', maxwidth - 1 ) + 1;
210 out.resize( std::max( len, minwidth ) );
217 struct tm localtm = time.local();
219 unsigned mday = localtm.tm_mday;
220 unsigned mon = localtm.tm_mon + 1;
221 unsigned year = ( localtm.tm_year > 80 ? localtm.tm_year - 80 : 0 );
222 unsigned sec = localtm.tm_sec / 2;
223 unsigned min = localtm.tm_min;
224 unsigned hour = localtm.tm_hour;
225 return ( mday << 16 | mon << 21 |
year << 25 | sec | min << 5 |
hour << 11 );
235 memset( &localtm, 0,
sizeof( localtm ) );
236 localtm.tm_mday = ( dosDate >> 16 ) & 0x1f;
237 localtm.tm_mon = ( ( dosDate >> 21 ) & 0xf ) - 1;
238 localtm.tm_year = ( ( dosDate >> 25 ) & 0x7f ) + 80;
239 localtm.tm_hour = ( dosDate >> 11 ) & 0x1f;
240 localtm.tm_min = ( dosDate >> 5 ) & 0x3f;
241 localtm.tm_sec = ( dosDate & 0x1f ) * 2;
242 localtm.tm_isdst = -1;
244 return Time( mktime( &localtm ), 0 );
tm local(int *nsecpart=0) const
Break up the time to the standard library representation, converting it first to local time.
int hour(bool local) const
Get the hour, numbered [0, 23].
std::string nanoformat(std::size_t minwidth=1, std::size_t maxwidth=9) const
Format the nanosecond fractional part of the time as a string.
static Time build(bool local, const tm &base, TimeSpan diff=0)
Construct a time from local time base and a delta diff.
int second(bool local) const
Get the seconds, numbered [0,61] (allowing one or two leap seconds, years with leap seconds can have ...
int month(bool local) const
Get the month, numbered [0,11].
const char * timezone(int *daylight=0) const
Return the local timezone name that applies at this time value.
int weekday(bool local) const
Get the day of week, numbered [0,6] and starting from Sunday.
int nsecond() const
Get the nanoseconds.
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
int minute(bool local) const
Get the minute, numbered [0, 59].
static Time fromDosDate(unsigned dosDate)
Convert the MS-DOS date dosDate into a Time.
bool isdst(bool local) const
Check whether daylight savings is in effect.
Time()=default
Initialize an empty (zero) time value.
int year(bool local) const
Get the year.
tm utc(int *nsecpart=0) const
Break up the time to the standard library representation, keeping it in UTC.
static Time current()
Returns the current time.
int day(bool local) const
Get the day of month, numbered [1,31].
static constexpr ValueType SEC_NSECS
Nanoseconds in one second.
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...
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...
void TimeAssert(bool cond, std::string_view msg="time assertion failed") const
static unsigned toDosDate(Time time)
Convert the Time t into a MS-DOS date format.
Define general base for Gaudi exception.
constexpr static const auto FAILURE
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...