jq icon indicating copy to clipboard operation
jq copied to clipboard

fromdate produces an Epoch timestamp that is one hour off

Open sgp opened this issue 3 years ago • 3 comments

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

🤷

sgp avatar Oct 12 '22 14:10 sgp

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

mkj-pendo avatar Oct 12 '22 14:10 mkj-pendo

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

sgp avatar Oct 12 '22 14:10 sgp

@mkj-pendo that checks out, as the code for mktime ... is messy.

sgp avatar Oct 12 '22 14:10 sgp

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 avatar Jul 09 '24 01:07 jmoldow

@jmoldow thanks for researching. @sgp are you able to reproduce with 1.7?

wader avatar Jul 09 '24 10:07 wader

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

sgp avatar Jul 12 '24 18:07 sgp