]> Savannah Git Hosting - gnulib.git/commitdiff
parse-datetime: fix debug message on lone year number
authorAssaf Gordon <assafgordon@gmail.com>
Thu, 5 Jan 2017 04:22:22 +0000 (23:22 -0500)
committerAssaf Gordon <assafgordon@gmail.com>
Thu, 5 Jan 2017 05:08:07 +0000 (00:08 -0500)
Input dates such as
  date -d "Apr 11 22:59:00 2011"
are parsed as date (Apr 11, with default year 2016), then time, then a
number (2011). Based on the combination of previously seen tokens,
'digits_to_date_time' determines 2011 to be a year value.

This fixes the debug messages to correctly show the updated year.

Before:
    $ date --debug -d 'Apr 11 22:59:00 2011'
    date: parsed date part: (Y-M-D) 2016-04-11
    date: parsed time part: 22:59:00
    date: parsed number part: today/this/now

After:
    $ ./src/date --debug -d 'Apr 11 22:59:00 2011'
    date: parsed date part: (Y-M-D) 2016-04-11
    date: parsed time part: 22:59:00
    date: parsed number part: year: 2011

* lib/parse-datetime.y (struct parser_control): Add 'year_seen',
'debug_year_seen' member fields.
(digits_to_date_time): Update 'year_seen' as needed.
(debug_print_current_time): Inform about year updates.
(parse_datetime2): Initialize year_seen,debug_year_seen member fields.

ChangeLog
lib/parse-datetime.y

index e2ca46b0a46038cdc14695aa2d87f4f3b954160e..316a890d88a21a98dc34bb14c93c74fb6c7be382 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
 2017-01-04  Assaf Gordon <assafgordon@gmail.com>
 
+       parse-datetime: fix debug message on lone year number
+       Input dates such as
+         date -d "Apr 11 22:59:00 2011"
+       are parsed as date (Apr 11, with default year 2016), then time, then a
+       number (2011). Based on the combination of previously seen tokens,
+       'digits_to_date_time' determines 2011 to be a year value.
+       This fixes the debug messages to correctly show the updated year.
+       Before:
+           $ date --debug -d 'Apr 11 22:59:00 2011'
+           date: parsed date part: (Y-M-D) 2016-04-11
+           date: parsed time part: 22:59:00
+           date: parsed number part: today/this/now
+       After:
+           $ ./src/date --debug -d 'Apr 11 22:59:00 2011'
+           date: parsed date part: (Y-M-D) 2016-04-11
+           date: parsed time part: 22:59:00
+           date: parsed number part: year: 2011
+       * lib/parse-datetime.y (struct parser_control): Add 'year_seen',
+       'debug_year_seen' member fields.
+       (digits_to_date_time): Update 'year_seen' as needed.
+       (debug_print_current_time): Inform about year updates.
+       (parse_datetime2): Initialize year_seen,debug_year_seen member fields.
+
        parse-datetime: fix local timezone debug messages
        "Local timezones" are strings that affect only DST relative to the
        default timezone. The debug messages in parse-datetime.y printed
index f41a234bea6daee7bd16a2017d2798889c0a5b7d..30488d68a0a178101261d808c8e5027f66297f35 100644 (file)
@@ -229,6 +229,7 @@ typedef struct
   size_t dsts_seen;
   size_t times_seen;
   size_t zones_seen;
+  size_t year_seen;
 
   /* if true, print debugging output to stderr */
   bool parse_datetime_debug;
@@ -240,6 +241,7 @@ typedef struct
   size_t debug_dsts_seen;
   size_t debug_times_seen;
   size_t debug_zones_seen;
+  size_t debug_year_seen;
 
   /* true if the user specified explicit ordinal day value, */
   bool debug_ordinal_day_seen;
@@ -264,7 +266,10 @@ digits_to_date_time (parser_control *pc, textint text_int)
 {
   if (pc->dates_seen && ! pc->year.digits
       && ! pc->rels_seen && (pc->times_seen || 2 < text_int.digits))
-    pc->year = text_int;
+    {
+      pc->year_seen++;
+      pc->year = text_int;
+    }
   else
     {
       if (4 < text_int.digits)
@@ -414,6 +419,16 @@ debug_print_current_time (const char* item, parser_control *pc)
       space = 1;
     }
 
+  if (pc->year_seen != pc->debug_year_seen)
+    {
+      if (space)
+        fputc (' ',stderr);
+      fprintf (stderr, _("year: %04ld"), pc->year.value);
+
+      pc->debug_year_seen = pc->year_seen;
+      space = 1;
+    }
+
   if (pc->times_seen != pc->debug_times_seen)
     {
       if (space)
@@ -1820,6 +1835,7 @@ parse_datetime2 (struct timespec *result, char const *p,
   pc.local_zones_seen = 0;
   pc.dsts_seen = 0;
   pc.zones_seen = 0;
+  pc.year_seen = 0;
   pc.parse_datetime_debug = (flags & PARSE_DATETIME_DEBUG)!=0;
   pc.debug_dates_seen = 0;
   pc.debug_days_seen = 0;
@@ -1827,6 +1843,7 @@ parse_datetime2 (struct timespec *result, char const *p,
   pc.debug_local_zones_seen = 0;
   pc.debug_dsts_seen = 0;
   pc.debug_zones_seen = 0;
+  pc.debug_year_seen = 0;
   pc.debug_ordinal_day_seen = false;
   pc.debug_default_input_timezone = 0;