diff --git a/.gitignore b/.gitignore index 01cd39276..ad9680b88 100644 --- a/.gitignore +++ b/.gitignore @@ -127,6 +127,7 @@ src/misc/*.o /test/test_metatile /test/test_coord_conversion /test/test_babel +/test/test_time # /po/ /po/Makefile.in.in diff --git a/test/Makefile.am b/test/Makefile.am index 762a08119..790c02d79 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -20,6 +20,7 @@ endif check_PROGRAMS = degrees_converter \ gpx2gpx \ test_vikgotoxmltool \ + test_time \ test_coord_conversion \ test_babel \ test_md5_hash \ @@ -78,6 +79,11 @@ test_vikgotoxmltool_LDADD = \ $(top_builddir)/src/libviking.a \ $(LDADD) +test_time_SOURCES = test_time.c +test_time_LDADD = \ + $(top_builddir)/src/libviking.a \ + $(LDADD) + test_coord_conversion_SOURCES = test_coord_conversion.c test_coord_conversion_LDADD = \ $(top_builddir)/src/libviking.a \ diff --git a/test/test_time.c b/test/test_time.c new file mode 100644 index 000000000..34be300a6 --- /dev/null +++ b/test/test_time.c @@ -0,0 +1,47 @@ +// Copyright: CC0 +// Compare timegm() with util_timegm() +// NB Need to force util_timegm() to use our fallback version +// Otherwise it will be using timegm() +#include +#include +#include +#include "util.h" + +// run like - 'for now': +// ./test_time $(date +"%Y:%m:%d-%H:%M:%S") +// Or manually substitute interesting dates as appropriate +// e.g. '2400:03:01-10:11:12' +int main(int argc, char *argv[]) +{ +#if !GLIB_CHECK_VERSION(2,36,0) + g_type_init (); +#endif + + if ( !argv[1] ) { + g_printerr ( "Nothing specified\n" ); + return 1; + } + + struct tm Time; + Time.tm_wday = 0; + Time.tm_yday = 0; + Time.tm_isdst = 0; // there is no DST in UTC + + sscanf(argv[1], "%d:%d:%d-%d:%d:%d", + &Time.tm_year, &Time.tm_mon, + &Time.tm_mday, &Time.tm_hour, + &Time.tm_min, &Time.tm_sec); + + Time.tm_year -= 1900; + Time.tm_mon -= 1; + + time_t thetime = util_timegm ( &Time ); + + if ( thetime != timegm ( &Time ) ) { + g_printf ("%s - %lu - %lu\n", argv[1], thetime, timegm(&Time)); + g_printf ("diff = %ld\n", (thetime - timegm(&Time))); + return 1; + } + + return 0; +}