30 memset( &val, 0,
sizeof( val ) );
45 if ( gettimeofday( &tv,
nullptr ) != 0 ) {
47 std::ostringstream tag, msg;
48 tag <<
"errno=" << errno;
49 if ( strerror_r( errno, buf, 256 ) == 0 ) {
52 msg <<
"Unknown error retrieving current time";
56 return Time( tv.tv_sec, tv.tv_usec * 1000 );
62 return Time(
local ? mktime( &tmp ) : timegm( &tmp ), 0 ) + diff;
76 localtime_r( &val, &retval );
78 gmtime_r( &val, &retval );
135 tm localtm =
local();
136 n = localtm.tm_gmtoff;
137 if ( daylight ) *daylight = localtm.tm_isdst;
147 tm localtm =
local();
148 if ( daylight ) *daylight = localtm.tm_isdst;
150 return tzname[localtm.tm_isdst > 0 ? 1 : 0];
161 std::string::size_type length = 0;
164 std::string::size_type pos = spec.find(
"%f" );
165 if ( std::string::npos != pos ) {
169 while ( std::string::npos != pos ) {
170 if ( pos != 0 && spec[pos - 1] !=
'%' ) { spec.replace( pos, 2, ms ); }
171 pos = spec.find(
"%f", pos + 1 );
174 const int MIN_BUF_SIZE = 128;
177 result.resize( std::max<std::string::size_type>(
178 result.size() * 2, std::max<std::string::size_type>( spec.size() * 2, MIN_BUF_SIZE ) ),
180 length = ::strftime( &result[0], result.size(), spec.c_str(), &time );
183 result.resize( length );
198 TimeAssert( ( minwidth >= 1 ) && ( minwidth <= maxwidth ) && ( maxwidth <= 9 ),
199 "nanoformat options do not satisfy: 1 <= minwidth <= maxwidth <= 9" );
204 std::ostringstream buf;
205 (void)buf.fill(
'0' );
208 std::string out = buf.str();
212 size_t len = out.find_last_not_of(
'0', maxwidth - 1 ) + 1;
214 out.resize( std::max( len, minwidth ) );
221 struct tm localtm = time.local();
223 unsigned mday = localtm.tm_mday;
224 unsigned mon = localtm.tm_mon + 1;
225 unsigned year = ( localtm.tm_year > 80 ? localtm.tm_year - 80 : 0 );
226 unsigned sec = localtm.tm_sec / 2;
227 unsigned min = localtm.tm_min;
228 unsigned hour = localtm.tm_hour;
229 return ( mday << 16 | mon << 21 |
year << 25 | sec | min << 5 |
hour << 11 );
239 memset( &localtm, 0,
sizeof( localtm ) );
240 localtm.tm_mday = ( dosDate >> 16 ) & 0x1f;
241 localtm.tm_mon = ( ( dosDate >> 21 ) & 0xf ) - 1;
242 localtm.tm_year = ( ( dosDate >> 25 ) & 0x7f ) + 80;
243 localtm.tm_hour = ( dosDate >> 11 ) & 0x1f;
244 localtm.tm_min = ( dosDate >> 5 ) & 0x3f;
245 localtm.tm_sec = ( dosDate & 0x1f ) * 2;
246 localtm.tm_isdst = -1;
248 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].
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 nanoformat(size_t minwidth=1, size_t maxwidth=9) const
Format the nanosecond fractional part of the time as a string.
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 const 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...