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
Windows and IANA Olson IDs #771
Comments
If you have the latest MSVC tools, and can set it C++20, this is really easy, and you don't need this lib. And you probably don't even need the offset. You can just ask it to change local time to system time and vice-versa. It is all part of the std library in C++20: #include <chrono>
#include <iostream>
int
main()
{
auto now_utc = std::chrono::system_clock::now();
std::cout << "system time is " << now_utc << '\n';
std::chrono::zoned_time zt{"America/Chicago", now_utc};
std::cout << "Time in Chicago is " << zt << '\n';
} Example output:
This library can be used if you can not yet move to C++20 (even on Windows). For example: #include "date/tz.h"
using date::operator<<;
#include <chrono>
#include <iostream>
int
main()
{
auto now_utc = std::chrono::system_clock::now();
std::cout << "system time is " << now_utc << '\n';
date::zoned_time zt{"America/Chicago", now_utc};
std::cout << "Time in Chicago is " << zt << '\n';
} Things are in |
I see, seems I was rather confused about some stuff. I was aware of Turns out I can just use multiple zoned_time structures and current_zone. Also, thanks for pointing out that this is available in C++20! |
Sounds like you've got it figured out. Fwiw, here's how I would do it: zoned_time zt_chicago{"America/Chicago", local_days{2015_y/12/06} + 12h};
zoned_time zt_local{current_zone(), zt_chicago};
cout << zt_local << '\n'; which for me just output:
(I'm in America/New_York) |
I'm going to apologize ahead of time for making such a spaghetti and meatballs issue. So while trying to get this working on Windows, I was actually using the MinGW ecosystem. Unfortunately, neither libc++ or libstdc++ supports the timezone portion of std::chrono (and I don't see any pending patches at the moment). As a result, I'm switching between using I actually looked at how STL does it, and they appear to once again rely on their ICU library in order to build the initial database meaning there's no need to connect to the internet to download/build a new database nor is there a need to keep the database up to date on the application side. Their ICU libraries are updated through system updates. Basically, I'm wanting a USE_OS_TZDB for Windows. While I'm aware (especially for Apple apparently) that the system timezone information may be wrong, I'd much prefer that not be my responsibility as a library/application writer. |
I hear you. But that is realistically not going to happen. I don't have that much time, nor a Windows development environment. Perhaps you could take from the MSVC code that reads from ICU? |
Welp, turns out Microsoft simply doesn't have a source for up-to-date timezone data, regardless of using the older Windows data or the libicu IANA data. Their version of libicu hasn't updated timezone data in 2 years and this reflects in their implementation of For now, I'll go the route of embedding my own timezone information and add a footnote that it may be better to implement timezones using their own format. I'll close this for now. |
I've been trying to figure out how Windows is supposed to interoperate with Olson IDs (e.g.
America/Chicago
). If I have a configuration file with an Olson ID, how do I figure out the offset of that on Windows compared to system time?That question led me to here. Basically, Microsoft started shipping a version of ICU that contains mappings from the Windows identifiers to Olson identifiers based on mappings from CLDR. An example of how this could work can be found here. I can then use this (tz) library to do the magic calculations.
Am I overthinking this? Would there be interest in supporting this to some extent for Windows?
The text was updated successfully, but these errors were encountered: