# HG changeset patch # User Ondřej Vašík # Date 1215080231 -7200 # Node ID 76127ff7748f38916bfffa0aaf3397713f4bb9c2 # Parent 38e0480fbb7186f57e8f5b43e715e48c4acf0bf8 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 diff -r 38e0480fbb71 -r 76127ff7748f ChangeLog --- 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 + + 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 Recognize 'foo_LIBRARIES += libgnu.a'. diff -r 38e0480fbb71 -r 76127ff7748f lib/getdate.y --- 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 diff -r 38e0480fbb71 -r 76127ff7748f tests/test-getdate.c --- 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; }