[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
parse-datetime.y & ISO8601 timestamps
From: |
J.T. Conklin |
Subject: |
parse-datetime.y & ISO8601 timestamps |
Date: |
Wed, 27 Apr 2011 08:47:58 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, berkeley-unix) |
First some background.
The continuous integration build framework I maintain at work uses
timestamp files for "last_build", "last_success", etc. The contents
of each file is the timestamp in ISO 8601 format (the inode mtime is
set to the same value, but thats besides the point).
I used this format thinking that the 'T' separator between date and
time would be more resistant to errors (shell quoting, etc.) than a
format that used spaces.
But someone reported that coreutils' date's -d option could not parse
this format. Fortunately, date -r could be used; but this challenges
my idea that the ISO format is more useful.
I've done some tweaks to parse-datetime.y as shown. Since 'T' now can
be either a millitary-style single character timezone and a separator,
I've special cased it as a token in the lexer. With the changes, the
function can parse the ISO 8601 / RFC 3339 YYYY-MM-DDTHH:MM:DD+MMSS
format (but not other valid ISO 8601 formats that omit -'s and :'s).
This adds another grammar conflict, but the parse-getdate test suite
still executes correctly.
I'm interested in comments on both the idea of supporting such time
formats, and whether there is a better implementation.
--jtc
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
index d77955f..0046d8d 100644
--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -285,8 +285,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 20 shift/reduce conflicts. */
-%expect 20
+/* This grammar has 21 shift/reduce conflicts. */
+%expect 21
%union
{
@@ -333,7 +333,9 @@ items:
;
item:
- time
+ datetime
+ { pc->times_seen++; pc->dates_seen++; }
+ | time
{ pc->times_seen++; }
| local_zone
{ pc->local_zones_seen++; }
@@ -348,6 +350,11 @@ item:
| hybrid
;
+datetime:
+ date 'T' time
+ ;
+
+
time:
tUNUMBER tMERIDIAN
{
@@ -405,6 +412,8 @@ zone:
{ pc->time_zone = $1 + 60; }
| tZONE tDST
{ pc->time_zone = $1 + 60; }
+ | 'T'
+ { pc->time_zone = HOUR(7); }
;
day:
@@ -794,7 +803,7 @@ static table const military_table[] =
{ "Q", tZONE, HOUR ( 4) },
{ "R", tZONE, HOUR ( 5) },
{ "S", tZONE, HOUR ( 6) },
- { "T", tZONE, HOUR ( 7) },
+ { "T", 'T', 0 },
{ "U", tZONE, HOUR ( 8) },
{ "V", tZONE, HOUR ( 9) },
{ "W", tZONE, HOUR (10) },
--
J.T. Conklin
- parse-datetime.y & ISO8601 timestamps,
J.T. Conklin <=