fix: populate timezone data when formatting time (#3203)
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. Apple's Libc implementation contains a bug which causes it to ignore the offset data present in the `struct tm` in favor of the older heuristic needed by legacy standards. This workaround temporarily sets the global timezone so it gets picked up during formatting.
This commit is contained in:
1 parent
b86ff49f46
commit
6d8e9f98ae
2 files changed
+58
-10
No files matched your search
@@ -694,4 +694,26 @@ printf '[\n {\n "a": 1\n }\n]\n' > $d/expected
|
||||
$JQ --indent 6 -n "[{a:1}]" > $d/out
|
||||
cmp $d/out $d/expected
|
||||
|
||||
if ! $msys && ! $mingw; then
|
||||
# Test handling of timezones -- #2429, #2475
|
||||
if ! r=$(TZ=Asia/Tokyo $JQ -rn '1731627341 | strflocaltime("%F %T %z %Z")') \
|
||||
|| [ "$r" != "2024-11-15 08:35:41 +0900 JST" ]; then
|
||||
echo "Incorrectly formatted local time"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! r=$(TZ=Europe/Paris $JQ -rn '1731627341 | strflocaltime("%F %T %z %Z")') \
|
||||
|| [ "$r" != "2024-11-15 00:35:41 +0100 CET" ]; then
|
||||
echo "Incorrectly formatted local time"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! r=$(TZ=Europe/Paris $JQ -rn '1731627341 | strftime("%F %T %z %Z")') \
|
||||
|| ( [ "$r" != "2024-11-14 23:35:41 +0000 UTC" ] \
|
||||
&& [ "$r" != "2024-11-14 23:35:41 +0000 GMT" ] ); then
|
||||
echo "Incorrectly formatted universal time"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in new issue
Block a user