fromdate produces an Epoch timestamp that is one hour off
Describe the bug
Parsing an ISO8601 timestamp yields a timestamp that is off by 3600 seconds.
To Reproduce
echo 1665511200 | jq todate | jq fromdate
1665514800
Expected behavior
Expected the round trip from todate (which produces an ISO8601) to fromdate would yield the same result.
Environment (please complete the following information):
- OS and Version: macOS Monterey 12.6, also reproduced on Linux (Fedora 34)
- jq version 1.6
Additional context
🤷
This is possibly related to DST.
On Fedora 36, jq 1.6:
$ date
Wed Oct 12 10:30:23 AM EDT 2022
$ echo 1665511200 | jq todate | jq fromdate
1665514800
$ export TZ=UTC
$ date
Wed Oct 12 02:31:08 PM UTC 2022
$ echo 1665511200 | jq todate | jq fromdate
1665511200
This is definitely mktime's fault, as fromdate is just an alias for strptime("%Y-%m-%dT%H:%M:%SZ")|mktime.
echo 1665511200 | jq -c 'todate|strptime("%Y-%m-%dT%H:%M:%SZ")'
[2022,9,11,18,0,0,2,283]
echo "[2022,9,11,18,0,0,2,283]" | jq mktime
1665514800
@mkj-pendo that checks out, as the code for mktime ... is messy.
I believe this is a duplicate of #2001 and can probably be closed, since it is fixed in jq 1.7 (though that version still isn't released to Debian and probably other systems as well).
@jmoldow thanks for researching. @sgp are you able to reproduce with 1.7?
Tried this on jq 1.7.1, and it looks good
❯ echo "[2022,9,11,18,0,0,2,283]" | jq mktime
1665511200
❯ echo 1665511200 | jq -c 'todate|strptime("%Y-%m-%dT%H:%M:%SZ")'
[2022,9,11,18,0,0,2,283]
❯ echo 1665511200 | jq todate | jq fromdate
1665511200