X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-parse-datetime.c;h=22fe9bc1194ac55edcab23eb4cdd8ec2df2d7efd;hb=2ae12d77e599965beb1483c10edb1f2f290bafc1;hp=4cb85d5aab6f50f6430015381b1020b5cc91e61d;hpb=c2ecbc9a8262595b27f741e41375d06213a30fb6;p=gnulib.git diff --git a/tests/test-parse-datetime.c b/tests/test-parse-datetime.c index 4cb85d5aa..22fe9bc11 100644 --- a/tests/test-parse-datetime.c +++ b/tests/test-parse-datetime.c @@ -36,7 +36,7 @@ #define LOG(str, now, res) (void) 0 #endif -static const char* const day_table[] = +static const char *const day_table[] = { "SUNDAY", "MONDAY", @@ -93,21 +93,18 @@ tm_diff (struct tm const *a, struct tm const *b) } #endif /* ! HAVE_TM_GMTOFF */ -long -gmt_offset() +static long +gmt_offset (time_t s) { - time_t now; long gmtoff; - time(&now); - #if !HAVE_TM_GMTOFF - struct tm tm_local = *localtime(&now); - struct tm tm_gmt = *gmtime(&now); + struct tm tm_local = *localtime (&s); + struct tm tm_gmt = *gmtime (&s); - gmtoff = tm_diff(&tm_local, &tm_gmt); + gmtoff = tm_diff (&tm_local, &tm_gmt); #else - gmtoff = localtime(&now)->tm_gmtoff; + gmtoff = localtime (&s)->tm_gmtoff; #endif return gmtoff; @@ -123,16 +120,17 @@ main (int argc _GL_UNUSED, char **argv) const char *p; int i; long gmtoff; + time_t ref_time = 1304250918; set_program_name (argv[0]); - gmtoff = gmt_offset(); + gmtoff = gmt_offset (ref_time); /* ISO 8601 extended date and time of day representation, 'T' separator, local time zone */ p = "2011-05-01T11:55:18"; - expected.tv_sec = 1304250918 - gmtoff; + expected.tv_sec = ref_time - gmtoff; expected.tv_nsec = 0; ASSERT (parse_datetime (&result, p, 0)); LOG (p, expected, result); @@ -142,7 +140,7 @@ main (int argc _GL_UNUSED, char **argv) /* ISO 8601 extended date and time of day representation, ' ' separator, local time zone */ p = "2011-05-01 11:55:18"; - expected.tv_sec = 1304250918 - gmtoff; + expected.tv_sec = ref_time - gmtoff; expected.tv_nsec = 0; ASSERT (parse_datetime (&result, p, 0)); LOG (p, expected, result); @@ -153,7 +151,7 @@ main (int argc _GL_UNUSED, char **argv) /* ISO 8601, extended date and time of day representation, 'T' separator, UTC */ p = "2011-05-01T11:55:18Z"; - expected.tv_sec = 1304250918; + expected.tv_sec = ref_time; expected.tv_nsec = 0; ASSERT (parse_datetime (&result, p, 0)); LOG (p, expected, result); @@ -163,7 +161,7 @@ main (int argc _GL_UNUSED, char **argv) /* ISO 8601, extended date and time of day representation, ' ' separator, UTC */ p = "2011-05-01 11:55:18Z"; - expected.tv_sec = 1304250918; + expected.tv_sec = ref_time; expected.tv_nsec = 0; ASSERT (parse_datetime (&result, p, 0)); LOG (p, expected, result); @@ -327,6 +325,8 @@ main (int argc _GL_UNUSED, char **argv) ASSERT (!parse_datetime (&result, p, &now)); p = "UTC+4:00 tomorrow ago"; ASSERT (!parse_datetime (&result, p, &now)); + p = "UTC+4:00 tomorrow hence"; + ASSERT (!parse_datetime (&result, p, &now)); p = "UTC+4:00 40 now ago"; ASSERT (!parse_datetime (&result, p, &now)); p = "UTC+4:00 last tomorrow"; @@ -345,6 +345,11 @@ main (int argc _GL_UNUSED, char **argv) LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec && result.tv_nsec == result2.tv_nsec); + p = "UTC+400 1 day hence"; + ASSERT (parse_datetime (&result2, p, &now)); + LOG (p, now, result2); + ASSERT (result.tv_sec == result2.tv_sec + && result.tv_nsec == result2.tv_nsec); now.tv_sec = 4711; now.tv_nsec = 1267; p = "UTC+400 yesterday";