2 // Compare timegm() with util_timegm()
3 // NB Need to force util_timegm() to use our fallback version
4 // Otherwise it will be using timegm()
6 #include <glib/gstdio.h>
10 // run like - 'for now':
11 // ./test_time $(date +"%Y:%m:%d-%H:%M:%S")
12 // Or manually substitute interesting dates as appropriate
13 // e.g. '2400:03:01-10:11:12'
14 int main(int argc
, char *argv
[])
16 #if !GLIB_CHECK_VERSION(2,36,0)
21 g_printerr ( "Nothing specified\n" );
28 Time
.tm_isdst
= 0; // there is no DST in UTC
30 sscanf(argv
[1], "%d:%d:%d-%d:%d:%d",
31 &Time
.tm_year
, &Time
.tm_mon
,
32 &Time
.tm_mday
, &Time
.tm_hour
,
33 &Time
.tm_min
, &Time
.tm_sec
);
38 time_t thetime
= util_timegm ( &Time
);
40 if ( thetime
!= timegm ( &Time
) ) {
41 g_printf ("%s - %lu - %lu\n", argv
[1], thetime
, timegm(&Time
));
42 g_printf ("diff = %ld\n", (thetime
- timegm(&Time
)));