Hi,

I noticed that

        date -d '5 days ago'

has as its counterpart

        date -d '5 days'

if you want to know what day it will be 5 days hence.  This is not
necessarily intuitive, and GNU date unfortunately doesn't have support for
the keyword "hence", meaning "from now".

The attached minor patch to lib/getdate.y fixes this, so that the symmetry
between "ago" and "hence" can be observed:

        date -d '3 days ago'
        date -d '3 days hence'

        date -d '8 hours ago'
        date -d '8 hours hence'

I'm also slightly concerned about the bit in lib/getdate.y's OtherTable
where "second" is commented out:

/*  { "second",         tUNUMBER,       2 }, */

I see that "second" as an ordinal specifier was removed because it
conflicts with "second" as a time unit.  That leads to the unfortunate
behavior

[zork(~)] date -d 'first Wednesday'
Wed Dec 15 00:00:00 PST 1999
[zork(~)] date -d 'second Wednesday'
Wed Dec 15 00:00:01 PST 1999
[zork(~)] date -d 'third Wednesday'
Wed Dec 29 00:00:00 PST 1999

Obviously the result is that GNU date thinks of "second Wednesday" as
equivalent to "first second Wednesday":

[zork(~)] date -d 'first minute Wednesday'
Wed Dec 15 00:01:00 PST 1999
[zork(~)] date -d 'first hour Wednesday'
Wed Dec 15 01:00:00 PST 1999
[zork(~)] date -d 'ninth hour Wednesday'
Wed Dec 15 09:00:00 PST 1999

Is a consistent solution in which "second" can be either an ordinal or a
time unit without provoking serious confusion or resulting in serious
ambiguity?

I tell people to use "first Wednesday+1 week" instead of "second Wednesday",
but that may not be intuitive.

One last thing: what would it take to support something like

        date -d 'November 1+fourth Wednesday'

in GNU date?  (That syntax is accepted, but it gives a peculiar response.)

-- 
Seth Schoen, Senior Linux Consultant, Linuxcare, Inc.
415.354.4878 x326 tel, 415.701.7457 fax
[EMAIL PROTECTED], http://www.linuxcare.com/
Linuxcare. At the center of Linux.
--- lib/getdate.y.orig  Sat Aug  7 02:39:05 1999
+++ lib/getdate.y       Tue Dec 14 17:11:11 1999
@@ -184,7 +184,7 @@
     enum _MERIDIAN     Meridian;
 }
 
-%token tAGO tDAY tDAY_UNIT tDAYZONE tDST tHOUR_UNIT tID
+%token tAGO tHENCE tDAY tDAY_UNIT tDAYZONE tDST tHOUR_UNIT tID
 %token tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
 %token tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE
 
@@ -347,6 +347,13 @@
        | relunit
        ;
 
+rel    : relunit tHENCE {
+            /* Nothing happens; default behavior for relative times.
+               Included for symmetry with tAGO. */
+       }
+       | relunit
+       ;
+
 relunit        : tUNUMBER tYEAR_UNIT {
            yyRelYear += $1 * $2;
        }
@@ -523,6 +530,7 @@
     { "eleventh",      tUNUMBER,       11 },
     { "twelfth",       tUNUMBER,       12 },
     { "ago",           tAGO,   1 },
+    { "hence",         tHENCE, 2 },
     { NULL, 0, 0 }
 };
 
--- doc/getdate.texi.orig       Wed Mar 25 05:40:21 1998
+++ doc/getdate.texi    Tue Dec 14 18:14:28 1999
@@ -384,6 +384,7 @@
 1 year ago
 3 years
 2 days
+3 weeks hence
 @end example
 
 @findex year @r{in date strings}
@@ -403,11 +404,14 @@
 accepted and ignored.
 
 @findex ago @r{in date strings}
+@findex hence @r{in date strings}
 The unit of time may be preceded by a multiplier, given as an optionally
 signed number.  Unsigned numbers are taken as positively signed.  No
 number at all implies 1 for a multiplier.  Following a relative item by
 the string @samp{ago} is equivalent to preceding the unit by a
-multiplicator with value @math{-1}.
+multiplicator with value @math{-1}.  Following a relative item by the
+string @samp{hence} has no effect, but may be useful to clarify that a
+relative time in the future is intended.
 
 @findex day @r{in date strings}
 @findex tomorrow @r{in date strings}

Reply via email to