19 using namespace Gaudi;
27 # define NOGDICAPMASKS
48 # include <sys/time.h>
69 # define SECS_1601_TO_1970 ( ( 369 * 365 + 89 ) * 86400ui64 )
73 static time_t timegm(
struct tm*
t ) {
75 time_t
t1 = mktime(
t );
77 gmtime_s( &gmt, &
t1 );
78 time_t
t2 = mktime( &gmt );
85 memset( &val, 0,
sizeof( val ) );
100 Time Time::from(
const FILETIME* systime ) {
105 t = (
t - SECS_1601_TO_1970 * (
SEC_NSECS / 100 ) ) * 100;
115 GetSystemTimeAsFileTime( &ftime );
116 return from( &ftime );
119 if ( gettimeofday( &tv,
nullptr ) != 0 ) {
121 std::ostringstream tag,
msg;
122 tag <<
"errno=" << errno;
123 if ( strerror_r( errno, buf, 256 ) == 0 ) {
126 msg <<
"Unknown error retrieving current time";
130 return Time( tv.tv_sec, tv.tv_usec * 1000 );
137 return Time(
local ? mktime( &tmp ) : timegm( &tmp ), 0 ) + diff;
151 localtime_r( &val, &
retval );
153 gmtime_r( &val, &
retval );
211 tm localtm =
local();
212 n = localtm.tm_gmtoff;
213 if ( daylight ) *daylight = localtm.tm_isdst;
218 localtime_s( &localtm, &utctime );
219 int savedaylight = localtm.tm_isdst;
221 gmtime_s( &gmt, &utctime );
223 gmt.tm_isdst = savedaylight;
224 n = utctime - mktime( &gmt );
226 if ( daylight ) *daylight = savedaylight;
234 # pragma warning( push )
235 # pragma warning( disable : 4996 )
242 tm localtm =
local();
243 if ( daylight ) *daylight = localtm.tm_isdst;
245 return tzname[localtm.tm_isdst > 0 ? 1 : 0];
248 # pragma warning( pop )
259 std::string::size_type length = 0;
262 std::string::size_type pos = spec.find(
"%f" );
263 if ( std::string::npos != pos ) {
267 while ( std::string::npos != pos ) {
268 if ( pos != 0 && spec[pos - 1] !=
'%' ) { spec.replace( pos, 2,
ms ); }
269 pos = spec.find(
"%f", pos + 1 );
272 const int MIN_BUF_SIZE = 128;
275 result.resize( std::max<std::string::size_type>(
276 result.size() * 2, std::max<std::string::size_type>( spec.size() * 2, MIN_BUF_SIZE ) ),
278 length = ::strftime( &result[0], result.size(), spec.c_str(), &
time );
281 result.resize( length );
296 TimeAssert( ( minwidth >= 1 ) && ( minwidth <= maxwidth ) && ( maxwidth <= 9 ),
297 "nanoformat options do not satisfy: 1 <= minwidth <= maxwidth <= 9" );
302 std::ostringstream buf;
303 (void)buf.fill(
'0' );
306 std::string
out = buf.str();
310 size_t len =
out.find_last_not_of(
'0', maxwidth - 1 ) + 1;
312 out.resize( std::max( len, minwidth ) );
319 struct tm localtm =
time.local();
321 unsigned mday = localtm.tm_mday;
322 unsigned mon = localtm.tm_mon + 1;
323 unsigned year = ( localtm.tm_year > 80 ? localtm.tm_year - 80 : 0 );
324 unsigned sec = localtm.tm_sec / 2;
325 unsigned min = localtm.tm_min;
326 unsigned hour = localtm.tm_hour;
327 return ( mday << 16 | mon << 21 |
year << 25 | sec | min << 5 |
hour << 11 );
337 memset( &localtm, 0,
sizeof( localtm ) );
338 localtm.tm_mday = ( dosDate >> 16 ) & 0x1f;
339 localtm.tm_mon = ( ( dosDate >> 21 ) & 0xf ) - 1;
340 localtm.tm_year = ( ( dosDate >> 25 ) & 0x7f ) + 80;
341 localtm.tm_hour = ( dosDate >> 11 ) & 0x1f;
342 localtm.tm_min = ( dosDate >> 5 ) & 0x3f;
343 localtm.tm_sec = ( dosDate & 0x1f ) * 2;
344 localtm.tm_isdst = -1;
346 return Time( mktime( &localtm ), 0 );