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


View this message in rfc822 format

From: Vincent Lefevre <vincent <at> vinc17.net>
To: Ulf Zibis <Ulf.Zibis <at> gmx.de>
Cc: 26101 <at> debbugs.gnu.org
Subject: bug#26101: Counterproductive calculation order in date
Date: Wed, 7 Feb 2018 01:37:34 +0100
On 2017-03-15 13:23:48 +0100, 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

Similarly:

zira% date +%Y-%m-%d -d '2003-02-01 - 1 month'
2003-01-01
zira% date +%Y-%m-%d -d '2003-02-01 - 31 days'
2003-01-01

but if I add "+ 1 month", I get different results:

zira% date +%Y-%m-%d -d '2003-02-01 - 31 days + 1 month'
2003-01-29
zira% date +%Y-%m-%d -d '2003-02-01 - 1 month + 1 month'
2003-02-01

Unfortunately this behavior, which is due to the fact that operations
are reordered to take into account years, then months, then days, is
not documented in the Coreutils manual.

-- 
Vincent Lefèvre <vincent <at> vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




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.