c++windowsdatecross-platform

date::make_zoned crash on Windows


I am writing a C++ cross-platform application for Windows 11 and CentOS7 (whose latest GCC version is 11).

My application has to use date.h of Mr. Howard Hinnant (and not std::chrono) for parsing timezone strings.

add_executable(myapp myapp.cpp)
set_target_properties(myapp PROPERTIES CXX_STANDARD 17)
target_link_libraries(myapp PRIVATE date::date date::date-tz)
std::string time_with_tz = "2024-09-30 14:53:27.123456 UTC";

std::stringstream ss(time_with_tz);
std::chrono::system_clock::time_point tp_with_tz;
date::from_stream(ss, "%F %T %Z", tp_with_tz); // date::parse does not work for me in both Win & Linux

date::format("%F %T %Z", date::make_zoned(date::current_zone(), tp_with_tz))

I have manually downloaded the latest tzdb-2024b.tar.lz from http://www.iana.org/time-zones and windowsZones.xml into C:\users\01258\downloads\tzdata.

My code in Linux works successfully but the same code crashes in Windows when calling date::make_zoned. What could be missing in my application? I even tried installing it using .\vcpkg.exe install date[remote-api]:x64-windows and it did not work either, still crashing in Windows.


Solution

  • Not positive, but I strongly suspect this is a duplicate of this issue.

    In a nutshell, tzdb-2024b introduced the string "April" when it intended "Apr" in one place. This is allowed according to the IANA spec, but broke several parsers, including mine, nonetheless.

    Two things have been done to fix this:

    1. You could upgrade the date lib to tip-of-master, or
    2. You could manually download tzdb-2024a.tar.lz, or
    3. Edit your IANA tzdata/northamercia file: change "April" to "Apr" on one (non comment) line (line 2634).