GNU bug report logs - #68064
Date addition error with “day Monthname” versus “Monthname day”

Previous Next

Package: coreutils;

Reported by: Larry Ploetz <lploetz <at> gmail.com>

Date: Wed, 27 Dec 2023 17:30:02 UTC

Severity: normal

Tags: notabug

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


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

From: Pádraig Brady <P <at> draigBrady.com>
To: Larry Ploetz <lploetz <at> gmail.com>, 68064 <at> debbugs.gnu.org
Subject: Re: bug#68064: Date addition error with “day Monthname” versus “Monthname day”
Date: Wed, 27 Dec 2023 19:27:04 +0000
tag 68064 notabug
close 68064
stop

On 27/12/2023 17:29, Larry Ploetz wrote:
> It seems like there might be a problem with date addition when the base
> date is specified as “day Monthname” instead of “Monthname day”, where
> the offset is being interpreted as an absolute year value. This may be
> locale-specific.
> 
>      <hostname>:bin larry$ locale
>      LANG="en_US.UTF-8"
>      LC_COLLATE="en_US.UTF-8"
>      LC_CTYPE="en_US.UTF-8"
>      LC_MESSAGES="en_US.UTF-8"
>      LC_MONETARY="en_US.UTF-8"
>      LC_NUMERIC="en_US.UTF-8"
>      LC_TIME="en_US.UTF-8"
>      LC_ALL=
>      <hostname>:bin larry$ ./date -d "$(./date -d today +%d\ %b) + 1 day"
>      Fri Dec 28 00:00:00 LMT 0001
>      <hostname>:bin larry$ ./date -d "$(./date -d today +%b\ %d) + 1 day"
>      Thu Dec 28 00:00:00 CST 2023
>      <hostname>:bin larry$ ./date --version
>      date (GNU coreutils) 9.4.97-98d463
>      Copyright (C) 2023 Free Software Foundation, Inc.
>      License GPLv3+: GNU GPL version 3 or later<https://gnu.org/licenses/gpl.html>.
>      This is free software: you are free to change and redistribute it.
>      There is NO WARRANTY, to the extent permitted by law.

This is due to ambiguity in date input formats.
Your case is:

  $ date --debug -d "27 Dec + 1 day"
  date: parsed date part: (Y-M-D) -001-12-27
  date: parsed relative part: +1 day(s)

A slightly adjusted case highlighting the ambiguity:

  $ date --debug -d "27 Dec + 1 week"
  date: parsed date part: (Y-M-D) -001-12-27
  date: parsed relative part: +7 day(s)

So really the solution here is to avoid the ambiguity
by explicitly specifying the year, or more abstractly
specifying "today" rather than a partial date.

Another gotcha highlighted by the --debug option above is:

  date: warning: using midnight as starting time: 00:00:00
  date: starting date/time: '(Y-M-D) 0001-12-27 00:00:00'
  date: warning: when adding relative days, it is recommended to specify noon

Another gotcha is that only English month abbreviations
are supported on input, so your command will fail in other locales.

For a summary of date input issues see:
https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e
https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html#index-date-input-formats

cheers,
Pádraig




This bug report was last modified 1 year and 203 days ago.

Previous Next


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