MiSawa / xq

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

strflocaltime does not respect TZ environment variable since 0.2.14 #106

Closed itchyny closed 2 years ago

itchyny commented 2 years ago
❯ env TZ=UTC+7 jq -n 'now | strflocaltime("%F %T %z")'
"2022-03-06 02:56:31 -0700"

❯ env TZ=UTC+7 xq -n 'now | strflocaltime("%F %T %z")'
"2022-03-06 18:56:34 +0900"

❯ xq --version
xq 0.2.14-ca02473b1522e4bc735a3106c25e44a140bfced6

But in 0.2.13, we get the same behavior as jq.

❯ env TZ=UTC+7 xq -n 'now | strflocaltime("%F %T %z")'
"2022-03-06 02:57:11 -0700"

❯ xq --version
xq 0.2.13-6bc93f85d86a2e8ea7fdd4a727aeef13c8f58686
MiSawa commented 2 years ago

Hmmmm, good find. Previously the local timezone lookup are basically done through tzset of C (which reads the contents of TZ environment variable and falls back to /etc/localtime in a nutshell) in the chrono crate, but I've changed it to use time crate in #34. Since this crate doesn't support the time zone name lookup, I use another crate time-tz, which appeared to implement the local timezone lookup by reading /etc/localtime and doesn't respect TZ environment variable. I've opened an issue there, but we might have to support in our side.... and fully supporting this is difficult, as TZ=":Cuba" for example require us to parse the timezone file /usr/share/zoneinfo/Cuba.