GNU bug report logs -
#50115
date command arithmetic involving the epoch produces "invalid date"
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 50115 in the body.
You can then email your comments to 50115 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#50115
; Package
coreutils
.
(Thu, 19 Aug 2021 01:48:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Jeremy Cantrell <jmcantrell <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Thu, 19 Aug 2021 01:48:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Using `date --utc --date="..."` with a date specification that
decrements by years that should result in epoch=0
(1969-12-31T23:59:59+00:00) produces an "invalid date" error message.
The following commands should illustrate the problem:
Notice that the only difference between the starting dates is 1 second.
```sh
$ date -u -d "1970-12-31T23:59:59+00:00 - 1 year"
date: invalid date ‘1970-12-31T23:59:59+00:00 - 1 year’
$ date -u -d "1970-12-31T23:59:58+00:00 - 1 year"
Wed Dec 31 11:59:58 PM UTC 1969
```
The dates are only considered invalid if they fall on epoch=0:
```sh
$ date -u -d "1971-12-31T23:59:59+00:00 - 2 year"
date: invalid date ‘1971-12-31T23:59:59+00:00 - 2 year’
$ date -u -d "1972-12-31T23:59:59+00:00 - 3 year"
date: invalid date ‘1972-12-31T23:59:59+00:00 - 3 year’
```
Going the other direction seems to work:
```sh
$ date -u -d "1969-01-01T00:00:00+00:00 + 1 year"
Thu Jan 1 12:00:00 AM UTC 1970
```
It only seems to error when decrementing by years:
```sh
date -u -d "1970-01-01T00:00:01+00:00 - 1 second"
Thu Jan 1 12:00:00 AM UTC 1970
```
It only seems to error when using --utc, because the following works
(my time zone is America/Chicago):
```sh
$ date -d "Wed Dec 31 06:00:00 PM CST 1970 - 1 year" +%s
0
```
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#50115
; Package
coreutils
.
(Thu, 19 Aug 2021 03:10:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 50115 <at> debbugs.gnu.org (full text, mbox):
On line 2160 in `./gnulib/lib/parse-datetime.y`, there's this:
```c
if (Start == (time_t) -1)
{
if (debugging (&pc))
dbg_printf (_("error: adding relative date resulted "
"in an invalid date: '%s'\n"),
debug_strfdatetime (&tm, &pc, dbg_tm,
sizeof dbg_tm));
goto fail;
}
```
This seems to indicate that, if the parsed value is -1, it's
considered an invalid date, but isn't -1 a valid date in epoch
seconds?
Passing --debug to the date shows the correct result, but claims it's invalid:
```sh
$ ./src/date --debug -u -d "1970-12-31T23:59:59+00:00 - 1 year"
date: parsed datetime part: (Y-M-D) 1970-12-31 23:59:59 UTC+00
date: parsed relative part: -1 year(s)
date: input timezone: parsed date/time string (+00)
date: using specified time as starting value: '23:59:59'
date: starting date/time: '(Y-M-D) 1970-12-31 23:59:59 TZ=+00'
date: warning: when adding relative months/years, it is recommended to
specify the 15th of the months
date: error: adding relative date resulted in an invalid date:
'(Y-M-D) 1969-12-31 23:59:59 TZ=+00'
./src/date: invalid date ‘1970-12-31T23:59:59+00:00 - 1 year’
```
Reply sent
to
Paul Eggert <eggert <at> cs.ucla.edu>
:
You have taken responsibility.
(Sat, 05 Feb 2022 21:56:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Jeremy Cantrell <jmcantrell <at> gmail.com>
:
bug acknowledged by developer.
(Sat, 05 Feb 2022 21:56:01 GMT)
Full text and
rfc822 format available.
Message #13 received at 50115-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Thanks for the bug report. I installed the attached patches to Gnulib
and to Coreutils, and the fix should be in the next Coreutils release.
[0001-parse-datetime-allow-calculations-to-yield-1.patch (text/x-patch, attachment)]
[0001-build-update-gnulib-submodule-to-latest.patch (text/x-patch, attachment)]
[0002-date-test-against-bug-50115.patch (text/x-patch, attachment)]
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 06 Mar 2022 12:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 2 years and 52 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.