[Top][All Lists]

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

Re: Command date doesnt work fine.

From: Eric Blake
Subject: Re: Command date doesnt work fine.
Date: Wed, 11 Jul 2007 06:36:00 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070604 Thunderbird/ Mnenhy/

Hash: SHA1

According to address@hidden on 7/11/2007 4:52 AM:
> address@hidden ~]# date --version
> date (coreutils) 5.2.1

This is several years out of date.  The latest stable version of coreutils
is 6.9; I suggest upgrading, and seeing if the problem remains in newer
releases.  It may also be dependent on what version of bison compiled
getdate.y, since we are dealing with an ambiguous parse.

But for what its worth, I see the following on a cygwin host, with a
timezone -7 hours from UTC:

$ date --version | head -n1
date (GNU coreutils) 6.9
$ date -d '1970/01/01 01:00:00 + 0 seconds' '+%F %T'
1969-12-31 18:00:01
$ date -d '1970/01/01 01:00:00' '+%F %T'
1970-01-01 01:00:00

The addition of '+ 0 seconds' changes the time by 7 hours and 1 second.
Hmm, that looks like the '+0' is being interpreted as a timezone
specifier, which then enables timezone correction (treating my entered
time with zone +0000 but displaying it with zone -0700), as well as taking
'seconds' as a directive to add one second.  In other words, the date
engine is parsing:

(1970/01/01 01:00:00 + 0) seconds

instead of

(1970/01/01 01:00:00) (+ 0 seconds)

An unambiguous approach is to put the relative information where it can't
be confused with a timezone:

$ date -d '+0 seconds 1970/01/01 01:00:00' '+%F %T'
1970-01-01 01:00:00
$ date -d '+60 seconds 1970/01/01 01:00:00' '+%F %T'
1970-01-01 01:01:00
$ date -d '+61 seconds 1970/01/01 01:00:00' '+%F %T'
1970-01-01 01:01:01

And if you really want seconds since the epoch (where 1970/01/01 01:00:00
is 3600 seconds), use the @ notation:

$ date -u -d @3600 '+%F %T'
1970-01-01 01:00:00

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

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