bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gnulib] Re: date -d 'Jun 05 23:59:59 GMT+00:00 2006'


From: Paul Eggert
Subject: [bug-gnulib] Re: date -d 'Jun 05 23:59:59 GMT+00:00 2006'
Date: Wed, 08 Dec 2004 14:37:22 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

On 2004-08-01 address@hidden (Karl Berry) writes:

> $ whois dredging.us
> ...
> Domain Registration Date:                    Thu Jun 27 02:47:46 GMT+00:00 
> 2002

OK, I added support to that date format to both CVS coreutils and
gnulib.  Here's the patch I installed (the NEWS patch is for
coreutils only):

2004-12-08  Paul Eggert  <address@hidden>

        * doc/getdate.texi (Time of day items, Time zone items):
        Describe new formats +00:00, UTC+00:00.
        * lib/getdate.y (textint): New member "negative".
        (time_zone_hhmm): New function.
        Expect 14 shift-reduce conflicts, not 13.
        (o_colon_minutes): New rule.
        (time, zone): Use it to add support for +HH:MM, UTC+HH:MM.
        (yylex): Set the "negative" member of signed numbers.
        * NEWS: Document the above, and put date changes together.

Index: doc/getdate.texi
===================================================================
RCS file: /fetish/cu/doc/getdate.texi,v
retrieving revision 1.25
diff -p -u -r1.25 getdate.texi
--- doc/getdate.texi    16 Nov 2004 08:16:57 -0000      1.25
+++ doc/getdate.texi    8 Dec 2004 22:20:09 -0000
@@ -259,10 +259,13 @@ which uses @samp{12m} for noon and @samp
 The time may alternatively be followed by a time zone correction,
 expressed as @address@hidden@address@hidden, where @var{s} is @samp{+}
 or @samp{-}, @var{hh} is a number of zone hours and @var{mm} is a number
-of zone minutes.  When a time zone correction is given this way, it
+of zone minutes.  You can also separate @var{hh} from @var{mm} with a colon.
+When a time zone correction is given this way, it
 forces interpretation of the time relative to
 Coordinated Universal Time (@sc{utc}), overriding any previous
-specification for the time zone or the local time zone.  The @var{minute}
+specification for the time zone or the local time zone.  For example,
address@hidden and @samp{+05:30} both stand for the time zone 5.5 hours
+ahead of @sc{utc} (e.g., India).  The @var{minute}
 part of the time of day may not be elided when a time zone correction
 is used.  This is the best way to specify a time zone correction by
 fractional parts of an hour.
@@ -283,6 +286,10 @@ Time.  Any included periods are ignored.
 non-daylight-saving time zone by the string @samp{DST} in a separate
 word (that is, separated by some white space), the corresponding
 daylight saving time zone may be specified.
+Alternatively, a non-daylight-saving time zone can be followed by a
+time zone correction, to add the two values.  This is normally done
+only for @samp{UTC}; for example, @samp{UTC+05:30} is equivalent to
address@hidden:30}.
 
 Time zone items other than @samp{UTC} and @samp{Z}
 are obsolescent and are not recommended, because they
Index: lib/getdate.y
===================================================================
RCS file: /fetish/cu/lib/getdate.y,v
retrieving revision 1.90
diff -p -u -r1.90 getdate.y
--- lib/getdate.y       16 Nov 2004 08:16:10 -0000      1.90
+++ lib/getdate.y       8 Dec 2004 22:20:09 -0000
@@ -108,6 +108,7 @@
    representation.  */
 typedef struct
 {
+  bool negative;
   long int value;
   size_t digits;
 } textint;
@@ -179,6 +180,7 @@ typedef struct
 union YYSTYPE;
 static int yylex (union YYSTYPE *, parser_control *);
 static int yyerror (parser_control *, char *);
+static long int time_zone_hhmm (textint, long int);
 
 %}
 
@@ -188,8 +190,8 @@ static int yyerror (parser_control *, ch
 %parse-param { parser_control *pc }
 %lex-param { parser_control *pc }
 
-/* This grammar has 13 shift/reduce conflicts. */
-%expect 13
+/* This grammar has 14 shift/reduce conflicts. */
+%expect 14
 
 %union
 {
@@ -207,7 +209,7 @@ static int yyerror (parser_control *, ch
 %token <textintval> tSNUMBER tUNUMBER
 %token <timespec> tSDECIMAL_NUMBER tUDECIMAL_NUMBER
 
-%type <intval> o_merid
+%type <intval> o_colon_minutes o_merid
 %type <timespec> seconds signed_seconds unsigned_seconds
 
 %%
@@ -263,7 +265,7 @@ time:
        pc->seconds.tv_nsec = 0;
        pc->meridian = $4;
       }
-  | tUNUMBER ':' tUNUMBER tSNUMBER
+  | tUNUMBER ':' tUNUMBER tSNUMBER o_colon_minutes
       {
        pc->hour = $1.value;
        pc->minutes = $3.value;
@@ -271,7 +273,7 @@ time:
        pc->seconds.tv_nsec = 0;
        pc->meridian = MER24;
        pc->zones_seen++;
-       pc->time_zone = $4.value % 100 + ($4.value / 100) * 60;
+       pc->time_zone = time_zone_hhmm ($4, $5);
       }
   | tUNUMBER ':' tUNUMBER ':' unsigned_seconds o_merid
       {
@@ -280,14 +282,14 @@ time:
        pc->seconds = $5;
        pc->meridian = $6;
       }
-  | tUNUMBER ':' tUNUMBER ':' unsigned_seconds tSNUMBER
+  | tUNUMBER ':' tUNUMBER ':' unsigned_seconds tSNUMBER o_colon_minutes
       {
        pc->hour = $1.value;
        pc->minutes = $3.value;
        pc->seconds = $5;
        pc->meridian = MER24;
        pc->zones_seen++;
-       pc->time_zone = $6.value % 100 + ($6.value / 100) * 60;
+       pc->time_zone = time_zone_hhmm ($6, $7);
       }
   ;
 
@@ -301,6 +303,8 @@ local_zone:
 zone:
     tZONE
       { pc->time_zone = $1; }
+  | tZONE tSNUMBER o_colon_minutes
+      { pc->time_zone = $1 + time_zone_hhmm ($2, $3); }
   | tDAYZONE
       { pc->time_zone = $1 + 60; }
   | tZONE tDST
@@ -523,6 +527,13 @@ number:
       }
   ;
 
+o_colon_minutes:
+    /* empty */
+      { $$ = -1; }
+  | ':' tUNUMBER
+      { $$ = $2.value; }
+  ;
+
 o_merid:
     /* empty */
       { $$ = MER24; }
@@ -709,6 +720,19 @@ static table const military_table[] =
 
 
 
+/* Convert a time zone expressed as HH:MM into an integer count of
+   minutes.  If MM is negative, then S is of the form HHMM and needs
+   to be picked apart; otherwise, S is of the form HH.  */
+
+static long int
+time_zone_hhmm (textint s, long int mm)
+{
+  if (mm < 0)
+    return (s.value / 100) * 60 + s.value % 100;
+  else
+    return s.value * 60 + (s.negative ? -mm : mm);
+}
+
 static int
 to_hour (long int hours, int meridian)
 {
@@ -960,6 +984,7 @@ yylex (YYSTYPE *lvalp, parser_control *p
            }
          else
            {
+             lvalp->textintval.negative = sign < 0;
              if (sign < 0)
                {
                  lvalp->textintval.value = - value;
Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.252
diff -p -u -r1.252 NEWS
--- NEWS        4 Dec 2004 14:15:46 -0000       1.252
+++ NEWS        8 Dec 2004 22:36:30 -0000
@@ -36,14 +36,6 @@ GNU coreutils NEWS                      
 
   cut's --output-delimiter=D option works with abutting byte ranges.
 
-  The --date (-d) option of "date" and "touch" is now pickier about date 
values:
-  it rejects dates like "January 32" that have out-of-range components.
-  Also, date values can now have leading TZ="..." assignments that override
-  the environment only while that date is being processed.  For example,
-  the following shell command converts from Paris to New York time:
-
-     TZ="America/New_York" date --date='TZ="Europe/Paris" 2004-10-31 06:30'
-
   du no longer segfaults when a subdirectory of an operand
   directory is removed while du is traversing that subdirectory.
   Since the bug was in the underlying fts.c module, it also affected
@@ -221,12 +213,25 @@ GNU coreutils NEWS                      
   du accepts a new option --files0-from=FILE, where FILE contains a
   list of NUL-terminated file names.
 
-  `date -d' and `touch -d' now accept integer counts of seconds since
-  1970 when prefixed by `@'.  For example, address@hidden' represents
-  1970-01-01 00:05:21 UTC.
+  Date syntax as used by date -d, date -f, and touch -d has been
+  changed as follows:
+
+    Dates like `January 32' with out-of-range components are now rejected.
+
+    Dates can have fractional time stamps like 2004-02-27 14:19:13.489392193.
+
+    Dates can be entered via integer counts of seconds since 1970 when
+    prefixed by `@'.  For example, address@hidden' represents 1970-01-01 
00:05:21 UTC.
+
+    Time zone corrections can now separate hours and minutes with a colon,
+    and can follow standard abbreviations like "UTC".  For example,
+    "UTC +0530" and "+05:30" are supported, and are both equivalent to "+0530".
+
+    Date values can now have leading TZ="..." assignments that override
+    the environment only while that date is being processed.  For example,
+    the following shell command converts from Paris to New York time:
 
-  `date -d', `date -f' and `touch -d' now handle fractional time
-  stamps like 2004-02-27 14:19:13.489392193.
+      TZ="America/New_York" date --date='TZ="Europe/Paris" 2004-10-31 06:30'
 
   `date' has a new option --iso-8601=ns that outputs
   nanosecond-resolution time stamps.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]