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: Jeremy Cantrell <jmcantrell <at> gmail.com>
To: 50115 <at> debbugs.gnu.org
Subject: bug#50115: Found the line where it is failing
Date: Wed, 18 Aug 2021 21:56:21 -0500
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’
```




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.