jq icon indicating copy to clipboard operation
jq copied to clipboard

strflocaltime always outputs +0000 for %Z

Open poettig opened this issue 2 years ago • 2 comments

Describe the bug jq outputs wrong timezone information when using strflocaltime with the %Z formatter:

└─$ timedatectl
               Local time: So 2022-05-08 13:48:24 CEST
           Universal time: So 2022-05-08 11:48:24 UTC
                 RTC time: So 2022-05-08 11:48:24
                Time zone: Europe/Berlin (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

└─$ jq -rn 'now | strflocaltime("%Y-%m-%dT%H:%M:%S%z")' 
2022-05-08T13:48:33+0000

To Reproduce TZ=Asia/Tokyo jq -rn 'now | strflocaltime("%Y-%m-%dT%H:%M:%S%z")'

└─$ TZ=Asia/Tokyo jq -rn 'now | strflocaltime("%Y-%m-%dT%H:%M:%S%z")' 
2022-05-08T20:51:59+0000

Expected behavior Output should be like the date command:

└─$ TZ=Asia/Tokyo date +"%Y-%m-%dT%H:%M:%S%z"
2022-05-08T20:51:20+0900

Environment (please complete the following information):

  • OS and Version: Linux; Reproduced on Manjaro and Debian Bullseye
  • jq version: 1.6

Additional context Might be related to https://github.com/stedolan/jq/issues/1912

poettig avatar May 08 '22 11:05 poettig

For the record, strflocaltime behaves properly on a Mac, whether using jq 1.5 or 1.6:

TZ=Asia/Tokyo jq-1.6 -rn 'now | strflocaltime("%Y-%m-%dT%H:%M:%S%z")'
2022-05-09T04:30:43+0900

TZ=Asia/Tokyojq-1.5 -rn 'now | strflocaltime("%Y-%m-%dT%H:%M:%S%z")'
2022-05-09T04:32:25+0900

pkoppstein avatar May 08 '22 19:05 pkoppstein

$ uname 
NetBSD
$ jq -rn 'now | strflocaltime("%Y-%m-%dT%H:%M:%S%z")'
2022-11-04T19:29:13-0500
$ date '+%Y-%m-%dT%H:%M:%S%z'
2022-11-04T19:29:21-0400

This is on NetBSD 9.3, so the problem isn't isolated to GNU+Linux. It looks like there's something funky with the way jq figures out the time zone.

trn1ty avatar Nov 04 '22 23:11 trn1ty