Subject: Re: bug#17161: closed (Re: bug#17161: Bug in date arithmetic of date)

From: "Marc R.J. Brevoort" <[email-masked]>
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@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@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@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@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
>
>