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

Make localtime() aware of timezone changes #1341

Closed
wants to merge 1 commit into from
Closed

Conversation

layus
Copy link

@layus layus commented Oct 4, 2019

According to POSIX.1-2004, localtime() is required to behave as though
tzset(3) was called, while localtime_r() does not have this requirement.
For portable code tzset(3) should be called before localtime_r().

See https://stackoverflow.com/questions/19170721/real-time-awareness-of-timezone-change-in-localtime-vs-localtime-r#answer-19170798 for more.

I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.

According to POSIX.1-2004, localtime() is required to behave as though
tzset(3) was called, while localtime_r() does not have this requirement.
For portable code tzset(3) should be called before localtime_r().

See https://stackoverflow.com/questions/19170721/real-time-awareness-of-timezone-change-in-localtime-vs-localtime-r#answer-19170798 for more.
@layus
Copy link
Author

layus commented Oct 4, 2019

Not too sure if the patch is valid for windows, and whether it is needed.

@vitaut
Copy link
Contributor

vitaut commented Oct 4, 2019

Thanks for the PR but the intent here is to have the localtime_r semantics. localtime is only used as a fallback on systems that don't have localtime_r.

@vitaut vitaut closed this Oct 4, 2019
@layus
Copy link
Author

layus commented Oct 4, 2019

Hi, thanks for you response. Please note that the intent is totally unclear from the only specification I could get:

Thread-safe time formatting #396

This adds thread-safe (at least on platforms that provide necessary extensions) replacement functions for std::localtime and std::gmtime. Alternatively they could be placed in a new source file time.cc, but time.h seems so empty right now...

If it is intended to replace std::localtime, it should have the same semantics. Why not call it localtime_r instead ? Note that the c++ std::localtime has exactly the same semantics as the c localtime: it calls tzset() (or works just as if it had been called) as per https://en.cppreference.com/w/cpp/chrono/c/localtime#Notes

@vitaut
Copy link
Contributor

vitaut commented Oct 4, 2019

I agree that it could be clearer. A PR clarifying the behavior in a comment is welcome. I don't think it's worth renaming the function to follow weird C naming convention (it would also be a breaking change).

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

Successfully merging this pull request may close these issues.

2 participants