changeset 29947:76127ff7748f

getdate.y: do not ignore TZ with relative day, month or year offset * lib/getdate.y (get_date): Move the tz-handling block to follow the relative-date-handling, since otherwise, the latter would clobber the sole output (an updated Start value) of the tz-handling block. * tests/test-getdate.c: Tests for the fix
author Ondřej Vašík <ovasik@redhat.com>
date Thu, 03 Jul 2008 12:17:11 +0200
parents 38e0480fbb71
children 7621b63e4ec3
files ChangeLog lib/getdate.y tests/test-getdate.c
diffstat 3 files changed, 44 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jul 03 20:17:33 2008 +0200
+++ b/ChangeLog	Thu Jul 03 12:17:11 2008 +0200
@@ -1,3 +1,11 @@
+2008-07-03  Ondřej Vašík  <ovasik@redhat.com>
+
+	getdate.y: do not ignore TZ with relative day, month or year offset
+	* lib/getdate.y (get_date): Move the tz-handling block to follow the
+	relative-date-handling, since otherwise, the latter would clobber the
+	sole output (an updated Start value) of the tz-handling block.
+	* tests/test-getdate.c: Tests for the fix
+
 2008-07-03  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
 	Recognize 'foo_LIBRARIES += libgnu.a'.
--- a/lib/getdate.y	Thu Jul 03 20:17:33 2008 +0200
+++ b/lib/getdate.y	Thu Jul 03 12:17:11 2008 +0200
@@ -1,8 +1,8 @@
 %{
 /* Parse a string into an internal time stamp.
 
-   Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
-   Foundation, Inc.
+   Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -1417,25 +1417,6 @@
 	    goto fail;
 	}
 
-      if (pc.zones_seen)
-	{
-	  long int delta = pc.time_zone * 60;
-	  time_t t1;
-#ifdef HAVE_TM_GMTOFF
-	  delta -= tm.tm_gmtoff;
-#else
-	  time_t t = Start;
-	  struct tm const *gmt = gmtime (&t);
-	  if (! gmt)
-	    goto fail;
-	  delta -= tm_diff (&tm, gmt);
-#endif
-	  t1 = Start - delta;
-	  if ((Start < t1) != (delta < 0))
-	    goto fail;	/* time_t overflow */
-	  Start = t1;
-	}
-
       /* Add relative date.  */
       if (pc.rel.year | pc.rel.month | pc.rel.day)
 	{
@@ -1458,6 +1439,27 @@
 	    goto fail;
 	}
 
+      /* The only "output" of this if-block is an updated Start value,
+	 so this block must follow others that clobber Start.  */
+      if (pc.zones_seen)
+	{
+	  long int delta = pc.time_zone * 60;
+	  time_t t1;
+#ifdef HAVE_TM_GMTOFF
+	  delta -= tm.tm_gmtoff;
+#else
+	  time_t t = Start;
+	  struct tm const *gmt = gmtime (&t);
+	  if (! gmt)
+	    goto fail;
+	  delta -= tm_diff (&tm, gmt);
+#endif
+	  t1 = Start - delta;
+	  if ((Start < t1) != (delta < 0))
+	    goto fail;	/* time_t overflow */
+	  Start = t1;
+	}
+
       /* Add relative hours, minutes, and seconds.  On hosts that support
 	 leap seconds, ignore the possibility of leap seconds; e.g.,
 	 "+ 10 minutes" adds 600 seconds, even if one of them is a
--- a/tests/test-getdate.c	Thu Jul 03 20:17:33 2008 +0200
+++ b/tests/test-getdate.c	Thu Jul 03 12:17:11 2008 +0200
@@ -51,6 +51,7 @@
 {
   bool ret;
   struct timespec result;
+  struct timespec result2;
   struct timespec now;
   const char *p;
 
@@ -85,5 +86,17 @@
   ASSERT (now.tv_sec + 4 * 60 * 60 == result.tv_sec
 	  && now.tv_nsec == result.tv_nsec);
 
+  /* test if timezone is not being ignored for day offset */
+  now.tv_sec = 4711;
+  now.tv_nsec = 1267;
+  p = "UTC+400 +24 hours";
+  ASSERT (get_date (&result, p, &now));
+  LOG (p, now, result);
+  p = "UTC+400 +1 day";
+  ASSERT (get_date (&result2, p, &now));
+  LOG (p, now, result2);
+  ASSERT (result.tv_sec == result2.tv_sec
+	  && result.tv_nsec == result2.tv_nsec);
+
   return 0;
 }