-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: populate timezone data when formatting time #3203
base: master
Are you sure you want to change the base?
Conversation
I'm afraid the timezone offset is not fixed even with this patch.
|
The `jv2tm` function was zeroing fields of `struct tm` that were not specified by the standard. However, depending on the libc this produced incorrect timezone data when used together with formatting functions. This change tries to fill the timezone data using either `mktime`, `timegm`, or manually.
e3873ef
to
48e7cc0
Compare
This issue is caused by a bug in the Apple's Libc implementation. Specifically in this line the I've added a workaround in the second commit that temporarily sets the global timezone to UTC if it is compiled for apple platforms. |
48e7cc0
to
0a35b19
Compare
Nice digging 👍 jq can be used as a library does that make it a bad idea to use Possible to add some tests for this? |
Apple's Libc implementation contains a bug which causees it to ignore the offset data present in the tm struct in favor of the older heuristic needed by legacy standards. This workaround temporarily sets the global timezone so it gets picked up during formatting.
0a35b19
to
465ca66
Compare
I've added some tests in |
465ca66
to
e3f94dd
Compare
I've disabled the tests on windows. The ucrt on Windows always uses the global settings for determining the timezone, which is documented in a note near the end of the strftime docs. I tried to make them work similarly to Apple workaround by using |
The
jv2tm
function was zeroing fields ofstruct tm
that were not specified by the standard. However, depending on the libc this produced incorrect timezone data when used together with formatting functions. This change tries to fill the timezone data using eithermktime
,timegm
, or manually.fixes #2475; fixes #2429.
Example:
TZ=Asia/Tokyo jq -rn '1731627341 | strflocaltime("%F %T %z %Z"), strftime("%F %T %z %Z")'
Before:
After: