Hi,
Richard Lewis said:
> date --date "1 day 1 hour ago"
>
> returns a date in the future. It works to do "1 day ago 1 hour ago".
> suggest outputting an error if the string can't be parsed - or at
> least documenting the syntax: the man-page suggests you can use natural
> language
> but this seems incorrect.
This is the behavior documented on the Texinfo manual [1]:
The unit of time may be preceded by a multiplier, given as an
optionally signed number. Unsigned numbers are taken as positively
signed. No number at all implies 1 for a multiplier. Following a
relative item by the string ‘ago’ is equivalent to preceding the
unit by a multiplier with value -1.
The --debug option is also helpful for understanding how this works. See
the following lines:
$ date --debug --date '1 day 1 hour ago' 2>&1 | grep 'adjustment'
date: after date adjustment (+0 years, +0 months, +1 days),
date: after time adjustment (-1 hours, +0 minutes, +0 seconds, +0 ns),
Thanks,
Collin
[1]
https://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html