coreutils
[Top][All Lists]
Advanced

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

[PATCH] date: support parsing of ISO-8601-with-"T" dates


From: Jim Meyering
Subject: [PATCH] date: support parsing of ISO-8601-with-"T" dates
Date: Fri, 19 Aug 2011 00:36:37 +0200

J. T. Conklin wrote the patch:
  http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/27929
to provide long-awaited support for parsing ISO 8601 "T"-separated
date-time strings.

Here's most of what I'll be adding in coreutils once that goes
into gnulib.  (along with an update to make coreutils use
the latest from gnulib, of course)

>From 9dd3a983f4999c75dc0da94c386e2ef3105ab906 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 19 Aug 2011 00:29:42 +0200
Subject: [PATCH] date: support parsing of ISO-8601-with-"T" dates

Thanks to an improvement in gnulib's parse-datetime module,
commands like this now succeed (output manually indented):
    $ ./date -u -d 2004-02-29T16:21:42.33+07:00 +%FT%T.%N%z
                   2004-02-29T09:21:42.330000000+0000
* tests/misc/date: Add a test to exercise the new-in-gnulib
parsing of ISO8601-with-"T" dates.
* NEWS (New features): Mention it.
---
 NEWS            |    6 ++++++
 tests/misc/date |    3 +++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index 6e24f5c..b23ebb1 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,12 @@ GNU coreutils NEWS                                    -*- 
outline -*-

 ** New features

+  date now accepts ISO 8601 date-time strings with "T" as the
+  separator.  It has long parsed dates like "2004-02-29 16:21:42"
+  with a space between the date and time strings.  Now it also parses
+  "2004-02-29T16:21:42" and fractional-second and time-zone-annotated
+  variants like "2004-02-29T16:21:42.333-07:00"
+
   md5sum accepts the new --strict option.  With --check, it makes the
   tool exit non-zero for any invalid input line, rather than just warning.
   This also affects sha1sum, sha224sum, sha384sum and sha512sum.
diff --git a/tests/misc/date b/tests/misc/date
index dd72544..6f7a530 100755
--- a/tests/misc/date
+++ b/tests/misc/date
@@ -29,6 +29,7 @@ $ENV{TZ} = 'UTC0';
 my $t0 = '08:17:48';
 my $d0 = '1997-01-19';
 my $d1 = "$d0 $t0 +0";
+my $dT = "${d0}T$t0+0"; # ISO 8601 with "T" separator

 my $ts = '08:17:49'; # next second
 my $tm = '08:18:48'; # next minute
@@ -72,6 +73,8 @@ my @Tests =
      # ['2', "-d '$d1' +'%c'", {OUT=>"Sun Jan 19 $t0 1997"}],

      ['3', "-d '$d1' +'%d_%D_%e_%h_%H'", {OUT=>"19_01/19/97_19_Jan_08"}],
+     ['3T',"-d '$dT' +'%d_%D_%e_%h_%H'", {OUT=>"19_01/19/97_19_Jan_08"}],
+
      ['4', "-d '$d1' +'%I_%j_%k_%l_%m'", {OUT=>"08_019_ 8_ 8_01"}],
      ['5', "-d '$d1' +'%M_%n_%p_%r'", {OUT=>"17_\n_AM_$t0 AM"}],
      ['6', "-d '$d1' +'%s_%S_%t_%T'", {OUT=>"853661868_48_\t_$t0"}],
--
1.7.6.857.gf34cf



reply via email to

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