Merge from coreutils.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Dec 2004 22:25:43 +0000 (22:25 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Dec 2004 22:25:43 +0000 (22:25 +0000)
doc/ChangeLog
doc/getdate.texi
lib/ChangeLog
lib/getdate.y

index 633db27d57e850486c95c46d282d8514e87664e0..974f421d175dda5a1c40ea688f179faaa01dafbb 100644 (file)
@@ -1,3 +1,8 @@
+2004-12-08  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * getdate.texi (Time of day items, Time zone items):
+       Describe new formats +00:00, UTC+00:00.
+
 2004-11-16  Paul Eggert  <eggert@cs.ucla.edu>
 
        * getdate.texi (General date syntax): "next" is 1, not 2.
index d1d42b3e35de9785b81f2200bf1408ec5191f9ca..2a7fbab9508da1db257ac9d73f496ac6f08fa696 100644 (file)
@@ -259,10 +259,13 @@ which uses @samp{12m} for noon and @samp{12pm} for midnight.)
 The time may alternatively be followed by a time zone correction,
 expressed as @samp{@var{s}@var{hh}@var{mm}}, 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,
+@samp{+0530} 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.  By following a
 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
+@samp{+05:30}.
 
 Time zone items other than @samp{UTC} and @samp{Z}
 are obsolescent and are not recommended, because they
index 05f13df9dfa63abf53f0c562ac96f1b8e8f66871..e0497acb3c667a997c8b8e81ee7909111b0ad632 100644 (file)
@@ -1,3 +1,12 @@
+2004-12-08  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * 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.
+
 2004-12-04  Paul Eggert  <eggert@cs.ucla.edu>
 
        Changes imported from coreutils.
index 8b8c11f4aeae301f42bb389167ee15e02bc73ece..6ffee30b96ffb5a96162c45b69c6f44fca3cffb6 100644 (file)
    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 *, char *);
 %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 *, char *);
 %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[] =
 
 \f
 
+/* 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 *pc)
            }
          else
            {
+             lvalp->textintval.negative = sign < 0;
              if (sign < 0)
                {
                  lvalp->textintval.value = - value;