[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#13058: European date format
From: |
Bob Proulx |
Subject: |
bug#13058: European date format |
Date: |
Sun, 2 Dec 2012 14:42:15 -0700 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Ohad Basan wrote:
> Hey
Hey back!
> Regarding 'date' command.
> the -d parameter doesn't know how to receive a european date format
> e.g. DD/MM/YYYY
I am assuming by "doesn't know how to receive" you mean it produces a
different result than one you wish? Because of course it parses it.
It just parses it (receives it) with a different result than you
wish. Please give an example of the behavior you see and what you
would like to see instead. Did you mean this:
$ date -d '12/15/2012 12:00' '+%F %T %z'
2012-12-15 12:00:00 -0700
Or this:
$ date -d '15/12/2012 12:00' '+%F %T %z'
date: invalid date ‘15/12/2012 12:00’
> I believe that it is a bug.
A typical format for digit/digit/digit is the US MM/DD/YYYY format.
Parsing the date as that format works fine.
$ date -R -d '12/02/2012 12:00'
Sun, 02 Dec 2012 12:00:00 -0700
$ date -R -u -d '12/02/2012'
Sun, 02 Dec 2012 00:00:00 +0000
Also using the truly ambiguous 2-digit year. Example of bad example.
$ date -R -d '12/02/12 12:00'
Sun, 02 Dec 2012 12:00:00 -0700
$ date -R -u -d '12/02/12'
Sun, 02 Dec 2012 00:00:00 +0000
How would you distinguish between MM/DD/YYYY and DD/MM/YYYY?
I think it is much, much better to avoid the ambiguity entirely by
using one of the standard date formats rather than a locale specific
format. As you can see in the above I always used the -R, --rfc-2822
option to produce standard and unambiguous formats.
Alternatives
I am very much an advocate of the '+%F %T %z' format which also
produces a stable result.
$ date '+%F %T %z'
2012-12-02 14:21:44 -0700
$ date -R -d '2012-12-02 14:21:44 -0700'
Sun, 02 Dec 2012 14:21:44 -0700
Note: Always either specify the time of day such as 12:00 as I did
above or specify use of UTC such as I did above with -u to avoid
problems with daylight savings time.
I also mention --rfc-3339 which is very useful in producing standard
unambiguous time strings.
--rfc-3339=TIMESPEC output date and time in RFC 3339 format.
TIMESPEC='date', 'seconds', or 'ns' for
date and time to the indicated precision.
Date and time components are separated by
a single space: 2006-08-07 12:34:56-06:00
$ date --rfc-3339=date
2012-12-02
$ date --rfc-3339=seconds
2012-12-02 14:34:38-07:00
$ date --rfc-3339=ns
2012-12-02 14:34:40.670385314-07:00
All of which may be parsed with date -d.
$ date -d "2012-12-02 14:34:40.670385314-07:00" '+%F %T.%N %z'
2012-12-02 14:34:40.670385314 -0700
Please also see the FAQ for date as there is much discussion there of
these and other issues.
http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e
Bob