coreutils
coreutils copied to clipboard
date: `--date` always results in invalid date
As the title says, everything I tried to pass to the --date option results in invalid date.
$ date --version
date 0.0.7
$ date --date="Sun, 29 Feb 2004 16:21:42 -0800"
date: invalid date 'Sun, 29 Feb 2004 16:21:42 -0800'
$ date --date="@1631716521"
date: invalid date '@1631716521'
I am currently using the version 0.0.7 on NixOS 20.05.
Also, thanks for all your work!
It currently uses chrono's parsing, which is very strict, something like a subset of ISO-8601. These are accepted:
date --date="1970-01-01T00:00:00Z"
date --date="1970-01-01T00:00:00+01:00"
(It doesn't seem to do anything with the timezone afterwards, though.)
Ah, okay! Thanks for the info. If this issue should be closed, you can do it or just let me know.
For others with a problem similar to mine: if you need to convert a unix epoch to retrieve the time between two moments, something like the following works good.
date --date="$(TZ=Etc/GMT printf '1970-01-01%(T%H:%M:%S)T+00:00\n' 12345)" -u +%H:%M
Specifically, I needed this to make this polybar script work.
Any trick for having relative dates? (E.g: all the ones visible here: https://www.cyberciti.biz/tips/linux-unix-get-yesterdays-tomorrows-date.html)
I can't find any relative date support in the code, but it's definitely something we should support, so feel free to open an issue for it!