Giuseppe Scrivano wrote: > what do you think of the following patch? When the same day as the > current one is provided then a week is added. It doesn't change the > behaviour for days in the past. > > It closes coreutils #25406. > > diff --git a/lib/getdate.y b/lib/getdate.y > index 877b264..8154fd9 100644 > --- a/lib/getdate.y > +++ b/lib/getdate.y > @@ -1435,7 +1435,7 @@ get_date (struct timespec *result, char const *p, > struct timespec const *now) > if (pc.days_seen && ! pc.dates_seen) > { > tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7 > - + 7 * (pc.day_ordinal - (0 < pc.day_ordinal))); > + + 7 * (pc.day_ordinal + (pc.day_ordinal > 0 && tm.tm_wday > == pc.day_number) - (0 < pc.day_ordinal))); > tm.tm_isdst = -1; > Start = mktime (&tm); > if (Start == (time_t) -1)
Nice! It certainly fixes the bug: Today is Friday, May 1: $ ./date +%a.%F Fri.2009-05-01 Before, "next friday" would give today's date: $ date -d 'next fri' +%a.%F Fri.2009-05-01 With your fix, it does what we expect: $ ./date -d 'next fri' +%a.%F Fri.2009-05-08 and doesn't appear to cause any regression. At least all of coreutils' tests still pass. This highlights that we need a new test or two to go along with your fix. Do you feel like adding a test along these lines to gnulib's tests/test-getdate.c? Also, for extra credit you can write a ChangeLog entry and send in "git format-patch" style output, as outlined in http://git.sv.gnu.org/cgit/coreutils.git/plain/HACKING Well, I thought better of it, and have done that latter for you ;-) I didn't want to wait, since I'm releasing coreutils-7.3 today. I adjusted the patch not to add a line longer than 80 and to use "0 < pc.day_ordinal" rather than the equivalent "pc.day_ordinal > 0". I expect to push this shortly. Thank you! Jim >From 372c3b4a79def664b8fa73316c35caf39bf93e2c Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano <gscriv...@gnu.org> Date: Fri, 1 May 2009 09:23:20 +0200 Subject: [PATCH] getdate: correctly interpret "next monday" when run on a Monday * lib/getdate.y (get_date): Correct the calculation of tm_mday so that e.g., "next tues" (when run on a tuesday) results in a date that is one week in the future, and not today's date. Reported by Tom Broadhurst http://savannah.gnu.org/bugs/?25406 and earlier by Martin Bernreuther. --- lib/getdate.y | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/getdate.y b/lib/getdate.y index 877b264..1964e9a 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -1,7 +1,7 @@ %{ /* Parse a string into an internal time stamp. - Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008 + Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -1435,7 +1435,10 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) if (pc.days_seen && ! pc.dates_seen) { tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7 - + 7 * (pc.day_ordinal - (0 < pc.day_ordinal))); + + 7 * (pc.day_ordinal + + (0 < pc.day_ordinal + && tm.tm_wday == pc.day_number) + - (0 < pc.day_ordinal))); tm.tm_isdst = -1; Start = mktime (&tm); if (Start == (time_t) -1) -- 1.6.3.rc3.212.g8c698