MiSawa / xq

Pure rust implementation of jq
MIT License
318 stars 18 forks source link

strptime/1 ignores timezone offset in datetime #111

Open itchyny opened 2 years ago

itchyny commented 2 years ago

Currently xq can parse but ignores timezone offset in strptime/1. This is actually the same behavior of jq, but considered as a critical bug when we handle datetime with timezone offsets (ref: https://github.com/stedolan/jq/issues/929, https://github.com/stedolan/jq/issues/2195).

❯ jq 'strptime("%Y-%m-%dT%H:%M:%S%z") | todate' <<< '"2022-03-12T09:00:00+0900"'
"2022-03-12T09:00:00Z"

❯ xq 'strptime("%Y-%m-%dT%H:%M:%S%z") | todate' <<< '"2022-03-12T09:00:00+0900"'
"2022-03-12T09:00:00Z"

❯ gojq 'strptime("%Y-%m-%dT%H:%M:%S%z") | todate' <<< '"2022-03-12T09:00:00+0900"'
"2022-03-12T00:00:00Z"

❯ xq --version
xq 0.2.16-a1cdd48497de46711dc12042ccb1a4cb4bc7fcea
MiSawa commented 2 years ago

I was aware of this issue and difference with gojq. Though I ignored it while I was replacing chrono with time, since it going to be complicated, especially when it comes to %Z, because of ambiguous timezone name and hardness of resolving timezone to offset....

But yeah, it'd be nice to support the feature. Though maybe we can only support %Z for UTC, GMT and perhaps the one (or more) from the locale.

itchyny commented 2 years ago

When this issue is resolved, it's useful if fromdateiso8601 supports timezone offsets. This is also reported to jq (https://github.com/stedolan/jq/issues/1053).