Philip Rowlands <[EMAIL PROTECTED]> wrote:
> On Tue, 30 Oct 2007, Jim Meyering wrote:
>> I'm hardly the authority on such TZ things, but would have thought
>> the invalid zones are those two intervals (one per line), which are
>> nominally two and one hours long. It looks like they're two
>> different views of the same two-real-hour interval. The first uses
>> the DST (isdst=1) times, and the second non-DST times.
>>
>> Date's -d option interprets an empty string just like "0", which is
>> interpreted as 00:00 in the current day.
>
> Ah, that makes the problem easier to present:
>
> $ export TZ=Europe/Paris
> $ export LD_PRELOAD=./clock_gettime.so
> $ FAKETIME=1193533200 date -d ""
> date: invalid date `'
> $ FAKETIME=1193533200 date -d "0"
> Sun Oct 28 00:00:00 CEST 2007
>
> -d "" and -d "0" are not equivalent in this case.
Hi Phil,
Thanks for keeping this going.
I tracked the difference to how the get_date function sets the
pc.times_seen member. That controls whether a tm.tm_isdst is initialized
to -1 (yes, for a date string of "0", no for the empty string).
That difference is what leads to a later mismatch between tm0 and tm,
causing mktime_ok to return false and thus making get_date fail.
The fix makes the code match the documentation by handling this case
as well as the case of a string containing only white space or a bare
TZ=... specification.
It'd be good to add a test for this.
Would you like to contribute a test case for gnulib,
since you've done most of the work already?
Paul owns the getdate module, so I'll wait for his ok
before pushing this:
Treat an empty date string exactly like "0".
* lib/getdate.y (get_date): Once any isspace or TZ= prefix is consumed,
if the remaining date string (to be parsed) is empty, use "0".
Signed-off-by: Jim Meyering <[EMAIL PROTECTED]>
---
lib/getdate.y | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/lib/getdate.y b/lib/getdate.y
index 80e484d..591c7f0 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -1238,6 +1238,12 @@ get_date (struct timespec *result, char const *p, struct
timespec const *now)
}
}
+ /* As documented, be careful to treat the empty string just like
+ a date string of "0". Without this, an empty string would be
+ declared invalid when parsed during a DST transition. */
+ if (*p == '\0')
+ p = "0";
+
pc.input = p;
pc.year.value = tmp->tm_year;
pc.year.value += TM_YEAR_BASE;
--
1.5.3.4.452.g09149
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils