Why the discrepancy in date?

Marius Gedminas marius at pov.lt
Sun Jan 8 17:10:30 UTC 2012


On Sun, Jan 08, 2012 at 05:09:48PM +0100, Nils Kassube wrote:
> Dotan Cohen wrote:
> > On Sun, Jan 8, 2012 at 14:06, Nils Kassube <kassube at gmx.net> wrote:
> > >> However, for dates in the past they do not:
> > >> ✈saturn:~$ date +%s -d 2006-12-31t22:00
> > >> 1167577200
> > > 
> > > Interesting - why do you use "t" instead of " " as a separator
> > > between date and time?
> > 
> > Because then I do not need the quotes. It is also ISO standard 8601:
> > http://en.wikipedia.org/wiki/ISO_8601
> 
> Ah, that's the reason - I didn't know about that standard.
> 
> > > So to me it looks like your "t" separator makes the date command
> > > use the time zone UTC+7 intead of your local time zone.
> > > Furthermore, if I specify a time zone together with your "t"
> > > separator, date complains about an invalid date:
...
> > I do not believe that there should be a difference when using the T
> > separator.
> 
> Agreed, it seems there is a bug in the date command. When it reads that 
> "t" separator it shouldn't take it as a time zone.

Note that it accepts almost any single-letter military timezone
specification[1] between the date and the time.

[1] http://en.wikipedia.org/wiki/List_of_military_time_zones

  $ LC_ALL=C TZ=UTC date -d 20120101a12:00
  Sun Jan  1 13:00:00 UTC 2012
  $ LC_ALL=C TZ=UTC date -d 20120101b12:00
  Sun Jan  1 14:00:00 UTC 2012
  $ LC_ALL=C TZ=UTC date -d 20120101c12:00
  Sun Jan  1 15:00:00 UTC 2012
  ...
  $ LC_ALL=C TZ=UTC date -d 20120101s12:00
  Sun Jan  1 06:00:00 UTC 2012
  $ LC_ALL=C TZ=UTC date -d 20120101t12:00
  Sun Jan  1 05:00:00 UTC 2012
  $ LC_ALL=C TZ=UTC date -d 20120101u12:00
  Sun Jan  1 04:00:00 UTC 2012

  $ LC_ALL=C TZ=UTC date -d 20120101z12:00
  Sun Jan  1 12:00:00 UTC 2012

I suspect the code was written before ISO-8601 even existed.

Marius Gedminas
-- 
If something has not yet gone wrong then it would ultimately have been
beneficial for it to go wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20120108/c35819c1/attachment.sig>


More information about the ubuntu-users mailing list