GNU bug report logs - #26101
Counterproductive calculation order in date

Previous Next

Package: coreutils;

Reported by: Ulf Zibis <Ulf.Zibis <at> gmx.de>

Date: Wed, 15 Mar 2017 00:42:01 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


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

From: Pádraig Brady <P <at> draigBrady.com>
To: Eric Blake <eblake <at> redhat.com>, Ulf Zibis <Ulf.Zibis <at> gmx.de>,
 26101 <at> debbugs.gnu.org
Subject: Re: bug#26101: Counterproductive calculation order in date
Date: Wed, 15 Mar 2017 08:53:31 -0700
On 15/03/17 05:44, Eric Blake wrote:
> On 03/15/2017 07:23 AM, Ulf Zibis wrote:
> 
>>
>> A more simple example without touch:
>> $ date +%F
>> 2017-03-15
>> $ date -d "-20 day" +%F
>> 2017-02-23
>> $ date -d "-20 day -2 month" +%F
>> 2016-12-26
>> $ date -d "-2 month -20 day" +%F
>> 2016-12-26
>>
>> In the 2nd example I would expect:
>> 2016-12-23
> 
> Why?  Both operations are computing: Subtract 20 days, and subtract 2
> months (equivalent to 60 days).  Subtraction is commutative, it doesn't
> matter which one you subtract first, if you are doing two subtractions.
> 
> Maybe you are confused on how date implements "subtract a month".  It
> does NOT do "subtract 28, 29, 30, or 31 days as appropriate", but rather
> does "subtract 30 days, for lack of anything better to do".  Maybe it
> could, but someone would have to write the patch.  Relative dates are
> HARD to compute, which is why --debug included this warning:

Yes that's an awkward gotcha (I'm not sure is related to the OP's issue).
I outlined a solution at http://bugs.gnu.org/18159#8
I didn't document in "coreutils gotchas" as it's covered in "coreutils FAQ",
though it might deserve a discussion there.

cheers,
Pádraig




This bug report was last modified 6 years and 265 days ago.

Previous Next


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