bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] test-parse-datetime.c: avoid new DST-related false positive test


From: Jim Meyering
Subject: [PATCH] test-parse-datetime.c: avoid new DST-related false positive test failure
Date: Sun, 30 Oct 2011 18:16:27 +0100

With last night's time switch here (from CEST to CST),
I noticed that coreutils' "make check" would fail like this:

  test-parse-datetime.c:142: assertion failed

Fixed with this:

>From 56ddf0fdeb52ce76718e0594db4f567401e90a2c Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 30 Oct 2011 18:12:54 +0100
Subject: [PATCH] test-parse-datetime.c: avoid new DST-related false positive
 test failure

* tests/test-parse-datetime.c (gmt_offset): Determine the "gmt_offset"
based on the time/date we'll convert, not the current time.
Otherwise, the moment we cross a DST boundary like today's in
Europe, (CEST to CET), that offset ends up being one hour off.
---
 ChangeLog                   |    8 ++++++++
 tests/test-parse-datetime.c |   22 ++++++++++------------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f4711dc..603a16f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-10-30  Jim Meyering  <address@hidden>
+
+       test-parse-datetime.c: avoid new DST-related false positive test failure
+       * tests/test-parse-datetime.c (gmt_offset): Determine the "gmt_offset"
+       based on the time/date we'll convert, not the current time.
+       Otherwise, the moment we cross a DST boundary like today's in
+       Europe, (CEST to CET), that offset ends up being one hour off.
+
 2011-10-27  Bruno Haible  <address@hidden>

        fstat: Tweak documentation.
diff --git a/tests/test-parse-datetime.c b/tests/test-parse-datetime.c
index b9d08a6..22fe9bc 100644
--- a/tests/test-parse-datetime.c
+++ b/tests/test-parse-datetime.c
@@ -94,20 +94,17 @@ tm_diff (struct tm const *a, struct tm const *b)
 #endif /* ! HAVE_TM_GMTOFF */

 static long
-gmt_offset ()
+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);
 #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);
--
1.7.7.1.476.g9890



reply via email to

[Prev in Thread] Current Thread [Next in Thread]