std::chrono::current_zone() on windows
Jonathan Wakely
jwakely.gcc@gmail.com
Wed Jul 2 10:13:55 GMT 2025
On Wed, 2 Jul 2025 at 09:15, Björn Schäpers <gcc@hazardy.de> wrote:
>
> Hi,
>
> currently current_zone() returns always "Etc/UTC", because (obviously)
> /etc/timezone, /var/db/zoneinfo, and /etc/sysconfig/clock do not exist. I'd like
> to fix that, but from the windows API you can't get IANA time zone names, for my
> current setting (Europe/Berlin) you'd get "W. Europe Standard Time".
>
> Howards date library [1] uses a xml file [2] which contains a mapping from the
> windows zones to the IANA time zones.
> The Microsoft STL uses ICU to get the current zone [3], which in turn, as far as
> I can tell also uses the windowsZones.xml.
>
> My question is, what would be accepted for libstdc++ rsp. is the best approach:
> 1. Use the windowsZones.xml and search manually for the right mapping. In this
> case I also need to know if there already exists code to parse xml.
Can we process the XML file when libstdc++ is built and generate a
lookup table in alphabetical order like:
const std::pair<std::string_view, std::string_view> zones[] {
{ "Dateline Standard Time", "Etc/GMT+12" },
{ "Morocco Standard Time", "Africa/Casablanca" },
{ "W. Europe Standard Time", "Europe/Berlin" },
...
}
If the Windows API gives you the mapZone/@other name (and not the
@territory?) then we would only need the territory="001" entry for
each mapZone. Searching in that table should be much faster than
parsing the whole XML file with all the redundant data.
> 2. Use ICU, which seems pretty sophisticated in getting the time zone right. I
> don't think it's a good thing to add ICU to libstdc++'s dependencies, such one
> would dynamically look for the libraries and the functions, that seems to be the
> way Microsofts STL doing it too.
>
> Kind regards,
> Björn.
>
> [1] https://github.com/HowardHinnant/date/
> [2]
> https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml
> [3]
> https://github.com/microsoft/STL/blob/313964b78a8fd5a52e7965e13781f735bcce13c5/stl/src/tzdb.cpp#L293
> [4]
> https://github.com/unicode-org/icu/blob/197be68a147938c38d227bd832fd3e23bec77283/icu4c/source/common/wintz.cpp#L88
More information about the Libstdc++
mailing list