GNU bug report logs - #50115
date command arithmetic involving the epoch produces "invalid date"

Previous Next

Package: coreutils;

Reported by: Jeremy Cantrell <jmcantrell <at> gmail.com>

Date: Thu, 19 Aug 2021 01:48:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Jeremy Cantrell <jmcantrell <at> gmail.com>
Subject: bug#50115: closed (Re: bug#50115: date command arithmetic
 involving the epoch produces "invalid date")
Date: Sat, 05 Feb 2022 21:56:01 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#50115: date command arithmetic involving the epoch produces "invalid date"

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 50115 <at> debbugs.gnu.org.

-- 
50115: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=50115
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jeremy Cantrell <jmcantrell <at> gmail.com>
Cc: Gnulib bugs <bug-gnulib <at> gnu.org>, 50115-done <at> debbugs.gnu.org
Subject: Re: bug#50115: date command arithmetic involving the epoch produces
 "invalid date"
Date: Sat, 5 Feb 2022 13:55:26 -0800
[Message part 3 (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)]
[Message part 7 (message/rfc822, inline)]
From: Jeremy Cantrell <jmcantrell <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: date command arithmetic involving the epoch produces "invalid date"
Date: Wed, 18 Aug 2021 20:43:01 -0500
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
```



This bug report was last modified 3 years and 165 days ago.

Previous Next


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