Skip to content

strftime uses wrong time zone for %Z #2475

Closed
@stollem

Description

@stollem

Describe the bug
strftime (in jq) is documented to always format times in the UTC time zone. However, if %Z is part of the format, will be replaced with the systems local time zone, which is inconsistent with the rest of the time formatting, resulting in unexpected outputs

To Reproduce
$ echo '1661932759' | TZ="Europe/Zurich" jq '. | strflocaltime("%Y-%m-%dT%H:%M:%S_%Z"), strftime("%Y-%m-%dT%H:%M:%S_%Z")'
"2022-08-31T09:59:19_CET"
"2022-08-31T07:59:19_CET"

Note: the output is very misleading... the time passed in is NOT 07:59:18 CET

Expected behavior
$ echo '1661932759' | TZ="Europe/Zurich" jq '. | strflocaltime("%Y-%m-%dT%H:%M:%S_%Z"), strftime("%Y-%m-%dT%H:%M:%S_%Z")'
"2022-08-31T09:59:19_CET"
"2022-08-31T07:59:19_UTC"

Note: the second line correct shows that the printed time is in UTC

Environment (please complete the following information):

  • Linux Debian testing
  • jq-1.6 (Debian package version 1.6-2.1)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions