GNU bug report logs -
#68064
Date addition error with “day Monthname” versus “Monthname day”
Previous Next
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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 68064 in the body.
You can then email your comments to 68064 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#68064
; Package
coreutils
.
(Wed, 27 Dec 2023 17:30:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Larry Ploetz <lploetz <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Wed, 27 Dec 2023 17:30:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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.
Written by David MacKenzie.
Thanks,
·Larry
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#68064
; Package
coreutils
.
(Wed, 27 Dec 2023 19:28:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 68064 <at> debbugs.gnu.org (full text, mbox):
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
Added tag(s) notabug.
Request was from
Pádraig Brady <P <at> draigBrady.com>
to
control <at> debbugs.gnu.org
.
(Wed, 27 Dec 2023 19:28:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
68064 <at> debbugs.gnu.org and Larry Ploetz <lploetz <at> gmail.com>
Request was from
Pádraig Brady <P <at> draigBrady.com>
to
control <at> debbugs.gnu.org
.
(Wed, 27 Dec 2023 19:28:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Thu, 25 Jan 2024 12:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 201 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.