-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Improve timezone tests #3240
Improve timezone tests #3240
Conversation
63b22f3
to
3479764
Compare
Demo: |
3479764
to
6ef8025
Compare
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I noticed the timezone issues too but didn't have time to look into them myself.
What is the purpose of setting the timezone in CI and can we avoid it to keep configs simpler?
test/chrono-test.cc
Outdated
#if defined(__MINGW32__) && !defined(_UCRT) | ||
spec_list = {"%Z"}; | ||
#else | ||
spec_list = {"%z", "%Z"}; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest moving this code to a separate function and reuse here and elsewhere in chrono-test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment clarifying why these are handled separately would be nice too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For loops are not equivalent.
First for
loop tests std::chrono::time_point
(std::chrono::system_clock::now()
) and std::tm
(in UTC).
Second for
loop tests timezone formatters only for std::tm
(in localtime).
I think we should not do this, since timezone support is a weak point of fmt and the standard library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vitaut
Comments added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean merging the for loops, just moving the selected block, namely
#if defined(__MINGW32__) && !defined(_UCRT)
spec_list = {"%Z"};
#else
spec_list = {"%z", "%Z"};
#endif
into a separate function (say, get_timezone_specs
) to keep the system-specific conditional compilation in one place.
Other than that, all looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vitaut
I don't understand how this will simplify the code.
The condition defined(__MINGW32__) && !defined(_UCRT)
is used 4 times in this test. Partially with precondition ifndef _WIN32
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not perfect but would be slightly cleaner because we could reuse this function in two of these places. Another option is to move the defined(__MINGW32__) && !defined(_UCRT)
condition into one place, define our own macro (e.g. FMT_HAS_C99_STRFTIME
) and reuse that in all places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I added macro FMT_HAS_C99_STRFTIME
.
@vitaut |
6ef8025
to
d7ab3f3
Compare
Sounds reasonable but is it possible to move changing the timezone to code instead of CI? |
Unfortunately, I am not aware of a cross-platform and universal API for changing the timezone settings. So I changed it at the CI settings level. I think it's more reliable. |
I understand that this is not are best solution, but I have no other universal solution. |
Signed-off-by: Vladislav Shchapov <[email protected]>
Signed-off-by: Vladislav Shchapov <[email protected]>
Signed-off-by: Vladislav Shchapov <[email protected]>
d7ab3f3
to
f848372
Compare
Thank you! |
Issues present after commit 115001a
std::tm
.We need to use
std::chrono
to format time with timezone.