Skip to content
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

Wrong timezone names in strftime/strflocaltime for DST #1912

Open
trantor opened this issue May 28, 2019 · 7 comments · May be fixed by #2863
Open

Wrong timezone names in strftime/strflocaltime for DST #1912

trantor opened this issue May 28, 2019 · 7 comments · May be fixed by #2863
Assignees

Comments

@trantor
Copy link
Contributor

trantor commented May 28, 2019

Describe the bug
jq does not print the timezone correctly expanding the %Z in the time format for strftime/strflocaltime when it comes to DST.
To Reproduce
Using the example from the wiki...

$ TZ=Europe/Rome ./jq-linux64 -cn 'now|strflocaltime("%Y-%m-%dT%H:%M:%S %Z")'
"2019-05-28T17:10:54 CET"

$ TZ=Europe/Rome date +"%Y-%m-%dT%H:%M:%S %Z"
2019-05-28T17:10:54 CEST

date reports, correctly, CEST as the timezone taking DST into account. jq does not.

Expected behavior
The output of jq to specify the correct timezone following DST

Environment (please complete the following information):

  • Linux Ubuntu 16.04
  • jq version 1.6
@nicowilliams
Copy link
Contributor

Huh, I think there's no real difference between strftime and strflocaltime...

Also, strftime(3) in glibc should be doing this for us, but evidently it's not, and the date(1) command is not calling strftime(3) either!

This looks like a bug in glibc, honestly, though we might be able to work around it.

To get at the DST TZ name we need to use localtime_r() and expect a tm_zone name from the broken-down time struct (struct tm), then use that in the formatting of time. So to work around this we'll need an autoconf test for tm_zone, and when it's present... use either a private strftime() or a wrapper that replaces %Z with the tm_zone. Ugh.

@krzyk
Copy link

krzyk commented Apr 7, 2021

This issue exists also in Debian testing in 2021.

@DehanLUO
Copy link

DehanLUO commented Jan 8, 2023

Same error on MacOS Monterey version 12.6.
This looks like a bug in function static jv tm2jv(struct tm *tm) and function static int jv2tm(jv a, struct tm *tm). The daylight saving time flag (tm_isdst), which is greater than zero if DST is in effect, is lost.
There is a 10-month-old branch 439cf72 there to fix it. I applied this fix locally. And it works on my machine.

@trantor
Copy link
Contributor Author

trantor commented Aug 27, 2023

@nicowilliams could we look back at this issue with new development?

@nicowilliams
Copy link
Contributor

nicowilliams commented Aug 28, 2023

Yes this is because the jq representation of broken-down time doesn't have a field for tm_isdst. We also don't look at or set tm_zone nor tm_gmtoff. Should be an easy fix.

@nicowilliams
Copy link
Contributor

Relatedly, mktime drops the fractional part of the seconds.

@trantor
Copy link
Contributor Author

trantor commented Sep 6, 2023

@nicowilliams #2863 seems to properly address the problem I originally reported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants