Web lists-archives.com

coreutils date behavior (buggy) (was: Re: policy around 'wontfix' bug tag)




On 2018-02-06 13:07:53 -0300, Lucas Castro wrote:
> Em 06-02-2018 10:38, Vincent Lefevre escreveu:
> > On 2018-02-06 13:48:19 +0100, Vincent Lefevre wrote:
> > > This is completely crazy:
> > > 
> > > zira% date +%Y-%m-%d -d '2003-09-01 1 day ago + 1 month'
> > > 2003-09-30
> > > zira% date +%Y-%m-%d -d '2003-09-01 1 day ago'
> > > 2003-08-31
> > > zira% date +%Y-%m-%d -d '2003-08-31 + 1 month'
> > > 2003-10-01
> > > 
> > > So, while '2003-09-01 1 day ago' gives 2003-08-31, the following
> > > are not equivalent:
> > >    * '2003-09-01 1 day ago + 1 month'
> > >    * '2003-08-31 + 1 month'
> > > 
> > > Where is the logic behind that?
> > Other ones:
> > 
> > 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
> > zira% date +%Y-%m-%d -d '2003-02-01 - 31 days + 1 month'
> > 2003-01-29
> I guess first step done is the sum and then, subtract 31 days.
> So, as the fev is a month just with 28 days, end up at 2003-01-29.

According to --debug, it seems that operations on years are done
first, then months, then days. But this is not documented in the
Coreutils manual.

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

There's a bug on the same subject:

  https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26101

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - 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)