[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH]: getdate.y TZ issue (patch#1 from set)
From: |
Jim Meyering |
Subject: |
Re: [PATCH]: getdate.y TZ issue (patch#1 from set) |
Date: |
Thu, 03 Jul 2008 16:17:05 +0200 |
Ondřej Vašík <address@hidden> wrote:
> Here is amended version of 1st patch from set - which is fixing ignored
> TZ for relative day/month/year offset. I added test to the gnu-lib
> getdate suite and ChangeLog entry.
>
> From 91a323b1d08d6023c2ebf10e0d86665dfed74a37 Mon Sep 17 00:00:00 2001
> From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <address@hidden>
> Date: Thu, 3 Jul 2008 12:17:11 +0200
> Subject: [PATCH] *lib/getdate.y: do not ignore TZ for relative day/month/year
> offset
>
> *lib/getdate.y (get_date): do not ignore TZ for relative day/month/year offset
> *tests/test-getdate.c: add test for day relative offset with specified TZ
[resending to bug-gnulib]
Thanks for adding those.
Since it's not obvious why this change solves the problem,
and usually we'd expect to find such explanation in the ChangeLog,
I rewrote the ChangeLog entry and added a comment in the code.
Here's what I expect to push:
>From cffd24f71262bdcfd4271f9cd9884705b3298f1a Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <address@hidden>
Date: Thu, 3 Jul 2008 12:17:11 +0200
Subject: [PATCH] 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
---
ChangeLog | 8 ++++++++
lib/getdate.y | 44 +++++++++++++++++++++++---------------------
tests/test-getdate.c | 13 +++++++++++++
3 files changed, 44 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b5d4f05..88bf9c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-07-03 Ondřej Vašík <address@hidden>
+
+ 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-02 Ondřej Vašík <address@hidden>
getdate.y: factor out common actions
diff --git a/lib/getdate.y b/lib/getdate.y
index 9171147..695fd59 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -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 @@ get_date (struct timespec *result, char const *p, struct
timespec const *now)
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 @@ get_date (struct timespec *result, char const *p, struct
timespec const *now)
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
diff --git a/tests/test-getdate.c b/tests/test-getdate.c
index 5bf3728..901adf9 100644
--- a/tests/test-getdate.c
+++ b/tests/test-getdate.c
@@ -51,6 +51,7 @@ main (int argc, char **argv)
{
bool ret;
struct timespec result;
+ struct timespec result2;
struct timespec now;
const char *p;
@@ -85,5 +86,17 @@ main (int argc, char **argv)
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;
}
--
1.5.6.1.110.gb707a
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [PATCH]: getdate.y TZ issue (patch#1 from set),
Jim Meyering <=