-
Notifications
You must be signed in to change notification settings - Fork 663
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
base: master
Are you sure you want to change the base?
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
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.