GNU bug report logs - #17161
date: confusing: "TIME -/+NUM" treated as time zone

Previous Next

Package: coreutils;

Reported by: "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>

Date: Tue, 1 Apr 2014 15:51:04 UTC

Severity: wishlist

To reply to this bug, email your comments to 17161 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#17161; Package coreutils. (Tue, 01 Apr 2014 15:51:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Tue, 01 Apr 2014 15:51:05 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>
To: bug-coreutils <at> gnu.org
Subject: Bug in date arithmetic of date
Date: Tue, 1 Apr 2014 13:30:16 +0200 (CEST)
Hi,

There seems to be some weirdness in date arithmetic when dates
include a time stamp (and all provided in ISO formatting):

Correct:

mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11" +"%Y-%m-%d %H:%M:%S"
2014-03-11 00:00:00

mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 -1 day" +"%Y-%m-%d %H:%M:%S"
2014-03-10 00:00:00

Incorrect:

mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 12:34 -2 hours" +"%Y-%m-%d 
%H:%M:%S"
2014-03-11 15:34:00
mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 12:34 +2 hours" +"%Y-%m-%d 
%H:%M:%S"
2014-03-11 11:34:00
mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 12:34 -1 day" +"%Y-%m-%d %H:%M:%S"
2014-03-12 13:34:00
mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 12:34 +1 day" +"%Y-%m-%d %H:%M:%S"
2014-03-12 11:34:00





Information forwarded to bug-coreutils <at> gnu.org:
bug#17161; Package coreutils. (Tue, 01 Apr 2014 16:03:02 GMT) Full text and rfc822 format available.

Message #8 received at 17161 <at> debbugs.gnu.org (full text, mbox):

From: "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>
To: 17161 <at> debbugs.gnu.org
Subject: Re: bug#17161: Acknowledgement (Bug in date arithmetic of date)
Date: Tue, 1 Apr 2014 18:01:58 +0200 (CEST)
Additional information -

The behaviour occurs in GNU coreutils 7.4. Version 8.5 appears to work 
correctly so this may be a dupe.




Added tag(s) notabug. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Tue, 01 Apr 2014 16:06:02 GMT) Full text and rfc822 format available.

Reply sent to Eric Blake <eblake <at> redhat.com>:
You have taken responsibility. (Tue, 01 Apr 2014 16:06:03 GMT) Full text and rfc822 format available.

Notification sent to "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>:
bug acknowledged by developer. (Tue, 01 Apr 2014 16:06:04 GMT) Full text and rfc822 format available.

Message #15 received at 17161-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>, 17161-done <at> debbugs.gnu.org
Subject: Re: bug#17161: Bug in date arithmetic of date
Date: Tue, 01 Apr 2014 10:05:27 -0600
[Message part 1 (text/plain, inline)]
tag 17161 notabug
thanks

On 04/01/2014 05:30 AM, Marc R.J. Brevoort wrote:
> Hi,
> 
> There seems to be some weirdness in date arithmetic when dates
> include a time stamp (and all provided in ISO formatting):

The weirdness is caused by your choice of locale, coupled with your
government's use of daylight savings, and not a bug in 'date'.

See also the FAQ:
https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e

> mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 12:34 -2 hours" +"%Y-%m-%d %H:%M:%S"
> 2014-03-11 15:34:00
> mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 12:34 +2 hours" +"%Y-%m-%d %H:%M:%S"
> 2014-03-11 11:34:00
> mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 12:34 -1 day" +"%Y-%m-%d %H:%M:%S"
> 2014-03-12 13:34:00
> mrjb <at> THE-D-MRJB:~$ date -d "2014-03-11 12:34 +1 day" +"%Y-%m-%d %H:%M:%S"
> 2014-03-12 11:34:00

These examples happen to cross a daylight savings boundary in your
current locale.  If you would amend your example to include time zone
names, you would see the name change, as evidence that the dates listed
are really 2 (or 24) hours apart, even though the wall clock time
appears to be 1 hour off.

You can also force date to operate on --utc, which does not observe
daylight savings, and therefore is immune to these oddities.

As such, I'm closing this as not a bug.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#17161; Package coreutils. (Wed, 02 Apr 2014 08:19:01 GMT) Full text and rfc822 format available.

Message #18 received at 17161 <at> debbugs.gnu.org (full text, mbox):

From: "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>
To: 17161 <at> debbugs.gnu.org
Subject: Re: bug#17161: closed (Re: bug#17161: Bug in date arithmetic of date)
Date: Wed, 2 Apr 2014 10:17:55 +0200 (CEST)
Hello,

As a heads-up, the explanation that this is due to time zone+locale doesn't make sense:

mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -1 day" +"%Y-%m-%d 
%H:%M:%S"
2014-03-12 13:34:56
mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -2 days" +"%Y-%m-%d 
%H:%M:%S"
2014-03-12 14:34:56
mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -3 days" +"%Y-%m-%d 
%H:%M:%S"
2014-03-12 15:34:56

The more days I subtract, the more hours are added. If this were a time 
zone issue, the amount of hours added would be constant but the 
resulting date would not.

Best,
Marc

On Tue, 1 Apr 2014, GNU bug Tracking System wrote:

> Your bug report
>
> #17161: Bug in date arithmetic of date
>
> which was filed against the coreutils package, has been closed.
>
> The explanation is attached below, along with your original report.
> If you require more details, please reply to 17161 <at> debbugs.gnu.org.
>
> -- 
> 17161: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17161
> GNU Bug Tracking System
> Contact help-debbugs <at> gnu.org with problems
>




Information forwarded to bug-coreutils <at> gnu.org:
bug#17161; Package coreutils. (Wed, 02 Apr 2014 11:28:02 GMT) Full text and rfc822 format available.

Message #21 received at 17161 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>, 17161 <at> debbugs.gnu.org,
 Bug-gnulib <bug-gnulib <at> gnu.org>
Subject: Re: bug#17161: closed (Re: bug#17161: Bug in date arithmetic of date)
Date: Wed, 02 Apr 2014 05:27:43 -0600
[Message part 1 (text/plain, inline)]
reopen 17161
thanks

On 04/02/2014 02:17 AM, Marc R.J. Brevoort wrote:
> Hello,
> 
> As a heads-up, the explanation that this is due to time zone+locale
> doesn't make sense:
> 
> mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -1 day" +"%Y-%m-%d
> %H:%M:%S"
> 2014-03-12 13:34:56
> mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -2 days"
> +"%Y-%m-%d %H:%M:%S"
> 2014-03-12 14:34:56
> mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -3 days"
> +"%Y-%m-%d %H:%M:%S"
> 2014-03-12 15:34:56
> 
> The more days I subtract, the more hours are added. If this were a time
> zone issue, the amount of hours added would be constant but the
> resulting date would not.

Thanks for persisting.  I was able to reproduce using coreutils.git, and
I can explain what's happening.  Date is parsing this as:

"(2014-03-11 12:34:56 -3) (days)"

that is, -3 is being treated as the timezone, since it occurs next to
the hour specification; then treating "days" as "+1 day" or "+24 hours".

Watch what happens when you reorder the line to force a different parse:

$ src/date --utc -d "-3 days 2014-03-11 12:34:56" +"%Y-%m-%d %H:%M:%S"
2014-03-08 12:34:56

It does indeed seem awkward that date is not parsing this as:

"(2014-03-11 12:34:56) (-3 days)"

but fixing that will require tweaks to the getdate.y parser in gnulib.
I've reopened the bug to track the issue with awkward precedence in the
parser.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 02 Apr 2014 11:34:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#17161; Package coreutils. (Wed, 02 Apr 2014 14:49:02 GMT) Full text and rfc822 format available.

Message #26 received at 17161 <at> debbugs.gnu.org (full text, mbox):

From: "Marc R.J. Brevoort" <mrjb <at> dnd.utwente.nl>
To: Eric Blake <eblake <at> redhat.com>
Cc: Bug-gnulib <bug-gnulib <at> gnu.org>, 17161 <at> debbugs.gnu.org
Subject: Re: bug#17161: closed (Re: bug#17161: Bug in date arithmetic of date)
Date: Wed, 2 Apr 2014 16:48:40 +0200 (CEST)
Hi,

Yes, I've come to the same conclusion (i.e. the numeric value in "+3 days" 
or "-2 days" being treated as time zone). The 8.5 coreutils I tested on 
is in a different time zone so it is possible it doesn't exhibit the same 
behavior because of that, and as such I can't actually tell whether the
behavior is actually resolved in coreutils 8.5.

I confirm that if I type,

mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 0 -1 day" +"%Y-%m-%d
 %H:%M:%S"

(i.e. using "0" as time zone), this gives the expected output,

2014-03-10 12:34:56

Best,
Marc


On Wed, 2 Apr 2014, Eric Blake wrote:

> reopen 17161
> thanks
>
> On 04/02/2014 02:17 AM, Marc R.J. Brevoort wrote:
>> Hello,
>>
>> As a heads-up, the explanation that this is due to time zone+locale
>> doesn't make sense:
>>
>> mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -1 day" +"%Y-%m-%d
>> %H:%M:%S"
>> 2014-03-12 13:34:56
>> mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -2 days"
>> +"%Y-%m-%d %H:%M:%S"
>> 2014-03-12 14:34:56
>> mrjb <at> THE-D-MRJB:~$ date --utc -d "2014-03-11 12:34:56 -3 days"
>> +"%Y-%m-%d %H:%M:%S"
>> 2014-03-12 15:34:56
>>
>> The more days I subtract, the more hours are added. If this were a time
>> zone issue, the amount of hours added would be constant but the
>> resulting date would not.
>
> Thanks for persisting.  I was able to reproduce using coreutils.git, and
> I can explain what's happening.  Date is parsing this as:
>
> "(2014-03-11 12:34:56 -3) (days)"
>
> that is, -3 is being treated as the timezone, since it occurs next to
> the hour specification; then treating "days" as "+1 day" or "+24 hours".
>
> Watch what happens when you reorder the line to force a different parse:
>
> $ src/date --utc -d "-3 days 2014-03-11 12:34:56" +"%Y-%m-%d %H:%M:%S"
> 2014-03-08 12:34:56
>
> It does indeed seem awkward that date is not parsing this as:
>
> "(2014-03-11 12:34:56) (-3 days)"
>
> but fixing that will require tweaks to the getdate.y parser in gnulib.
> I've reopened the bug to track the issue with awkward precedence in the
> parser.
>
> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>




Removed tag(s) notabug. Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Tue, 08 Apr 2014 17:25:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#17161; Package coreutils. (Sat, 20 Oct 2018 03:15:01 GMT) Full text and rfc822 format available.

Message #31 received at 17161 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Eric Blake <eblake <at> redhat.com>, "Marc R.J. Brevoort"
 <mrjb <at> dnd.utwente.nl>, 17161 <at> debbugs.gnu.org
Subject: Re: bug#17161: date: confusing: "TIME -/+NUM" treated as time zone
Date: Fri, 19 Oct 2018 21:13:55 -0600
severity 17161 wishlist
retitle 17161 date: confusing: "TIME -/+NUM" treated as time zone
stop

(triaging old bugs)

Hello,

On 02/04/14 05:27 AM, Eric Blake wrote:
> On 04/02/2014 02:17 AM, Marc R.J. Brevoort wrote:
>>
>> The more days I subtract, the more hours are added. If this were a time
>> zone issue, the amount of hours added would be constant but the
>> resulting date would not.
> 
> Thanks for persisting.  I was able to reproduce using coreutils.git, and
> I can explain what's happening.  Date is parsing this as:
> 
> "(2014-03-11 12:34:56 -3) (days)"
[...]
> It does indeed seem awkward that date is not parsing this as:
> 
> "(2014-03-11 12:34:56) (-3 days)"
> 
> but fixing that will require tweaks to the getdate.y parser in gnulib.
> I've reopened the bug to track the issue with awkward precedence in the
> parser.

In the mean time, date gained the "--debug" option that makes
diagnosing these issues somewhat easier.

Due to the way the date parser works, the following
rules apply:

1.
Time (HH:MM:SS) followed by a plus/minus character
and a number - ALWAYS parsed as time zone.
The unit that followed (e.g. "days" / "minutes")
are then taken to be of value 1 (e.g. 1 day, 1 minute).

Examples:

  ## This is "Timezone=3, plus one day"
  $ date --debug -d "2014-03-11 12:34:56 +3 days"
  date: parsed date part: (Y-M-D) 2014-03-11
  date: parsed time part: 12:34:56 UTC+03
  date: parsed relative part: +1 day(s)
  date: input timezone: parsed date/time string (+03)
  [...]
  Wed Mar 12 03:34:56 MDT 2014

  ## This is "Timezone=-10, plus one month"
  $ date --debug -d "2014-03-11 12:34:56 -10 months"
  date: parsed date part: (Y-M-D) 2014-03-11
  date: parsed time part: 12:34:56 UTC-10
  date: parsed relative part: +1 month(s)
  date: input timezone: parsed date/time string (-10)
  [...]
  Fri Apr 11 16:34:56 MDT 2014


2.
Time (HH:MM:SS) followed by a number without plus/minus sign,
The number applies to the units.

  ## This is "time, plus 7 seconds"
  $ date --debug -d "2014-03-11 12:34:56 7 seconds"
  date: parsed date part: (Y-M-D) 2014-03-11
  date: parsed time part: 12:34:56
  date: parsed relative part: +7 seconds
  [...]
  Tue Mar 11 12:35:03 MDT 2014

3.
To subtract units (e.g. three days) without using a minus character
(i.e. forcing rule #2 instead of triggering rule #1), use the word "ago":

  ## This is "time - 7 seconds"
  $ date --debug -d "2014-03-11 12:34:56 7 seconds ago"
  date: parsed date part: (Y-M-D) 2014-03-11
  date: parsed time part: 12:34:56
  date: parsed relative part: -7 seconds
  [...]
  Tue Mar 11 12:34:49 MDT 2014

  ## This is 3 days subtraction
  $ date --debug -d "2014-03-11 12:34:56 3 days ago"
  date: parsed date part: (Y-M-D) 2014-03-11
  date: parsed time part: 12:34:56
  date: parsed relative part: -3 day(s)
  [...]
  Sat Mar  8 12:34:56 MST 2014

Or use Eric's suggestion of putting the "-3 days"
before the date.

4.
Combining a time zone and a unit value is valid,
e.g.

  ## Timezone = -10, 9 days subtraction
  $ date --debug -d "2014-03-11 12:34:56 -10 -9 days"
  date: parsed date part: (Y-M-D) 2014-03-11
  date: parsed time part: 12:34:56 UTC-10
  date: parsed relative part: -9 day(s)
  date: input timezone: parsed date/time string (-10)
  [...]
  Sun Mar  2 15:34:56 MST 2014

----

As Eric wrote above, modifying the parser could be done in gnulib.
Not so much a technical problem, but very likely to be backward-
incompatible in a way that will break many many existing scripts.

As such, I'm marking this as "wishlist", but keeping it open -
discussion is welcomed to continue by replying to this thread.

regards,
 - assaf





Severity set to 'wishlist' from 'normal' Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 20 Oct 2018 03:15:02 GMT) Full text and rfc822 format available.

Changed bug title to 'date: confusing: "TIME -/+NUM" treated as time zone' from 'Bug in date arithmetic of date' Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 20 Oct 2018 03:15:02 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 193 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.