We are currently in a funny situation where GNU date can't parse its own
output:

  $ date --date="$(date)"
  date: invalid date ‘Mon  2 Feb 16:37:46 GMT 2015’

This is not aesthetically pleasing at the very least.

Signed-off-by: Chris Lamb <ch...@chris-lamb.co.uk>
---
 lib/parse-datetime.y | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)


-- 
Chris Lamb
@lolamby / chris-lamb.co.uk
From cd10931b5ff3bd2d0deb9eab5b85b46eccd8acbd Mon Sep 17 00:00:00 2001
From: Chris Lamb <ch...@chris-lamb.co.uk>
Date: Mon, 2 Feb 2015 16:38:59 +0000
Subject: [PATCH] lib/parse-datetime.y: Add ability to parse output of GNU
 date(1)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We are currently in a funny situation where GNU date can't parse its own
output:

  $ date --date="$(date)"
  date: invalid date ‘Mon  2 Feb 16:37:46 GMT 2015’

This is not aesthetically pleasing at the very least.

Signed-off-by: Chris Lamb <ch...@chris-lamb.co.uk>
---
 lib/parse-datetime.y | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
index 1b1fec7..9bacd32 100644
--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -290,8 +290,8 @@ set_hhmmss (parser_control *pc, long int hour, long int minutes,
 %parse-param { parser_control *pc }
 %lex-param { parser_control *pc }
 
-/* This grammar has 31 shift/reduce conflicts. */
-%expect 31
+/* This grammar has 32 shift/reduce conflicts. */
+%expect 32
 
 %union
 {
@@ -358,12 +358,27 @@ item:
 
 datetime:
     iso_8601_datetime
+  | gnu_date_default_format
   ;
 
 iso_8601_datetime:
     iso_8601_date 'T' iso_8601_time
   ;
 
+/* "%a %b %e %H:%M:%S %Z %Y" from coreutils:src/date.c to support
+   date --date="$(date)". We ignore the day of the week. */
+gnu_date_default_format:
+    tDAY tUNUMBER tMONTH tUNUMBER ':' tUNUMBER ':' tUNUMBER tZONE tUNUMBER
+      {
+        pc->day = $2.value;
+        pc->month = $3;
+        set_hhmmss (pc, $4.value, $6.value, $8.value, 0);
+        pc->time_zone = $9;
+        pc->year.value = -$10.value;
+        pc->year.digits = $10.digits;
+      }
+  ;
+
 time:
     tUNUMBER tMERIDIAN
       {
-- 
2.1.0

Reply via email to