Add missing trailing dot in sentences
[viking/guyou.git] / test / test_time.c
blob34be300a6dc1ade11c53c27735155b889f75e467
1 // Copyright: CC0
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()
5 #include <glib.h>
6 #include <glib/gstdio.h>
7 #include <time.h>
8 #include "util.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)
17 g_type_init ();
18 #endif
20 if ( !argv[1] ) {
21 g_printerr ( "Nothing specified\n" );
22 return 1;
25 struct tm Time;
26 Time.tm_wday = 0;
27 Time.tm_yday = 0;
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);
35 Time.tm_year -= 1900;
36 Time.tm_mon -= 1;
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)));
43 return 1;
46 return 0;