-
Notifications
You must be signed in to change notification settings - Fork 685
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
ADD windows support for USE_SYSTEM_TZ_DB #611
Conversation
return get_tzdb().locate_zone( | ||
#if WIN32 && USE_OS_TZDB | ||
// When USE_OS_TZDB=ON, the tz_name needs to be a valid path. | ||
// For timezone labeling consistency in Windows, switch "/" to "\". | ||
// This will allow for tz_name to have consistent naming regardless of | ||
// if USE_OS_TZDB is ON. | ||
std::regex_replace(tz_name, std::regex("\\/"), "\\") | ||
#else | ||
tz_name | ||
#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.
Instead of using std::regex
, why not std::replace
? Here you just need to replace a single character.
Edit: oh, tz_name
is a const&
, would it be possible to change it to an std::string
passed by value? You'd have to create a copy of the string in either case, but at least with replace
you don't need to use regex
(that is broken on some old compilers)
return get_tzdb().locate_zone( | |
#if WIN32 && USE_OS_TZDB | |
// When USE_OS_TZDB=ON, the tz_name needs to be a valid path. | |
// For timezone labeling consistency in Windows, switch "/" to "\". | |
// This will allow for tz_name to have consistent naming regardless of | |
// if USE_OS_TZDB is ON. | |
std::regex_replace(tz_name, std::regex("\\/"), "\\") | |
#else | |
tz_name | |
#endif | |
); | |
#if WIN32 && USE_OS_TZDB | |
// When USE_OS_TZDB=ON, the tz_name needs to be a valid path. | |
// For timezone labeling consistency in Windows, switch "/" to "\". | |
// This will allow for tz_name to have consistent naming regardless of | |
// if USE_OS_TZDB is ON. | |
std::replace(tz_name.begin(), tz_name.end(), '/', '\\'); | |
#endif | |
return get_tzdb().locate_zone(tz_name); |
I'm interested in these changes from a packaging perspective - this is pretty stale though, is there likely to be any movement on merging this in? |
For Windows platforms I strongly encourage people to migrate to C++20 |
According to Microsoft documentation, time zone support is only available on
If my project is compiled with C++20, i will not be able to use it on Windows Server 2019, am i right ? |
@wabscale can you comment on the utility of the |
That appears to be a mistake on my part. If this ever makes it into this library, this PR will need to be rewritten anyway. My original repo is many commits behind because of how long this issue has been open. |
* Add patches for v3.0.0 and v2.4.1 that hotfix the changes present in HowardHinnant/date#611 on to these older versions. This will allow all versions of date currently on CCI to utilise the tz package as a data source for the timezone database. Some additional modification of the build system was required in these patches to ensure a consistent interface across versions. Only the minimal changes necessary to introduce desired features were made, preserving deficiencies associated with older versions of date.
* Add patches for v3.0.0 and v2.4.1 that hotfix the changes present in HowardHinnant/date#611 on to these older versions. This will allow all versions of date currently on CCI to utilise the tz package as a data source for the timezone database. Some additional modification of the build system was required in these patches to ensure a consistent interface across versions. Only the minimal changes necessary to introduce desired features were made, preserving deficiencies associated with older versions of date.
* Add tz recipe as a dependency to provide a way of easily consuming/maintaining and upgrading the timezone database * Apply patch from HowardHinnant/date#807 to add the ability to specify the tz database by environment variable * Deprecate `use_system_tz_db` in favour of `with_tzdb` option to handle all mutually exclusive options * Add `with_db_format` option to provide flexibility in how the tz package is consumed. This implementation superesedes conan-io#16285 and conan-io#21719. In the case of conan-io#21719, it turned out that HowardHinnant/date#611 was not mature enough to provide the ability for the date library to read zic-compiled binary variants of the tzdb on Windows. To take an iterative approach, this PR aims to extract the elements that worked from conan-io#21719, which was the use of an environment variable to inject the conan packaged tz database. Use of a binary database has been marked as an invalid configuration on Windows. This functionality can be added at a later date. This pull request is blocked on conan-io#21671, which packages the source database in the tz recipe and makes this the default configuration since this is the only database that can be parsed consistently on all major platforms. Closes conan-io#16204
We have been using these changes to package this project for conda-forge - and I can confirm that it performs as expected. One way to make the patch super minimal is to simply use After all, the resulting changes would not be very windows specific:
Would you consider such a change @HowardHinnant ? |
As someone who succeeded using native C++20 |
This is really a shame that this has been closed unimplemented. It seems like a small change that would benefit those of use that have to support older OS versions. Just because std::chrono works now doesn't mean this isn't useful. Comments like "look what i did to port to c++20 so this isn't necessary to anyone else" are unhelpful ... In my particular case I am using c++20 and now need to fix a crash on older OS's and was actually led here from this microsoft/STL#1911 where date is a recommended solution. as a preview poster said
Windows 10 Iot/Enterprise, Server 2019 and other LTSB releases are "supported" by microsoft til 2029. Anyway I am mostly just venting because much of the development world is so quick to say, "oh just update to the latest" and really ignores the fact that a very large segment of software that still needs support and is under current development is running on older hardware with older OSes. I am glad date is here, and this PR maybe something i can use... (I was just so disappointed to get error C1189: #error: "USE_OS_TZDB can not be used on Windows") |
No rush - I had to work around the buggy STL implementation so I made https://github.com/basilgello/date/tree/tz-windows but in case something older than Windows 10 1703 is to be used, there is even another one implementation in progress, using "just" WinAPI. |
@basilgello hey thanks! I tried it out and got it to work on windows 11 (there were some types in tz.cpp that were included from stl/src/tzdb.cpp that were conflicting (i didn't investigate why i just commented them out to get it to compile). But when I tried it on 1809 I found it still tries to load icu.dll (which is not installed until 1903)... The code appears to attempt to use the icuin and icuuc dlls to get the functions but maybe that code is unfinished/untested? I could make a PR with the changes if you wanted to see them. (it didn't take very long to fix) |
For 1703 to 1903 the icuin/icuuc.dll must be loaded. I had no chance to test that codepath, so if you confirm it tries to load wrong dll, I can fix it. |
I have not PR'd the Windows tz support yet but I am glad to add your commit into my branch to preserve attribution! :) |
Windows support for USE_SYSTEM_TZ_DB
These changes add support for the USE_SYSTEM_TZ_DB option on windows. These changes increase the speed of timezone conversion operations by many orders of magnitude (see benchmarks below).
The majority of the changes are in the
init_tzdb
function. There I added support for the windows file API to load the timezone database off of disk.This Addresses...
Configuration
Along with these changes, I've added the option to specify the location of the zoneinfo TZDIR by environment variable. To my knowledge, there is no one standard place for the system tz database to live on windows. This means that for those to choose to use USE_SYSTEM_TZ_DB on windows will need to compile their own tz database from iana and specify its location via the TZDIR environment variable. It is my belief that this trade off is well worth it. The performance benefits speak for themselves.
Benchmarks
To test the benefits of the changes I ran this basic benchmark that times many timezone conversions.
Using the regular (non system) timezone database on windows, I get these results:
With these changes, and a compiled iana database:
Overall these changes allow for about ~7x faster timezone conversions on Windows.