Subject: date command arithmetic involving the epoch produces "invalid date"
From: Jeremy Cantrell <[email-masked]>
To: [email-masked]
Date: Wed, 18 Aug 2021 20:43:01 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

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
```