[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#26101: Counterproductive calculation order in date
From: |
Pádraig Brady |
Subject: |
bug#26101: Counterproductive calculation order in date |
Date: |
Wed, 15 Mar 2017 08:53:31 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
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
- bug#26101: Counterproductive calculation order in date, Ulf Zibis, 2017/03/14
- bug#26101: Counterproductive calculation order in date, Eric Blake, 2017/03/14
- bug#26101: Counterproductive calculation order in date, Ulf Zibis, 2017/03/15
- bug#26101: Counterproductive calculation order in date, Eric Blake, 2017/03/15
- bug#26101: Counterproductive calculation order in date, Ulf Zibis, 2017/03/15
- bug#26101: Counterproductive calculation order in date, Assaf Gordon, 2017/03/15
- bug#26101: Counterproductive calculation order in date, Assaf Gordon, 2017/03/15
- bug#26101: Counterproductive calculation order in date, Ulf Zibis, 2017/03/15
- bug#26101: Counterproductive calculation order in date, Eric Blake, 2017/03/15
- bug#26101: Counterproductive calculation order in date, Ulf Zibis, 2017/03/15
- bug#26101: Counterproductive calculation order in date,
Pádraig Brady <=
- bug#26101: Counterproductive calculation order in date, Assaf Gordon, 2017/03/15
- bug#26101: Counterproductive calculation order in date, Ulf Zibis, 2017/03/15