Skip to content
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

<chrono>: get_tzdb runtime_error on old Windows #3853

Closed
lat9nq opened this issue Jul 9, 2023 · 2 comments
Closed

<chrono>: get_tzdb runtime_error on old Windows #3853

lat9nq opened this issue Jul 9, 2023 · 2 comments

Comments

@lat9nq
Copy link

lat9nq commented Jul 9, 2023

Describe the bug

Using the function std::chrono::get_tzdb() on Windows 10 1809 throws a runtime_error.

Command-line test case

cmake_minimum_required(VERSION 3.12)

project(tzdb_test VERSION 1.0)

add_executable(tzdb_test
    main.cpp)

if (MSVC)
    target_compile_options(tzdb_test PRIVATE
        /std:c++20)
endif()
// main.cpp
#include <chrono>
#include <cstdio>
#include <stdexcept>
#include <string_view>

int main() {
  std::string location_name;
  try {
    const struct std::chrono::tzdb &time_zone_data = std::chrono::get_tzdb();
    const std::chrono::time_zone *current_zone = time_zone_data.current_zone();
    std::string_view current_zone_name = current_zone->name();
    location_name = current_zone_name;
  } catch (std::runtime_error &runtime_error) {
    location_name = std::string{"FAILURE: "} + runtime_error.what();
  }

  std::printf("%s\n", location_name.c_str());

  return 0;
}
PS C:\Temp> mkdir build
PS C:\Temp> cd build
PS C:\Temp\build> cmake ..
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.20348.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.36.32532.0
-- The CXX compiler identification is MSVC 19.36.32532.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (6.9s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Temp/build
PS C:\Temp\build> cmake --build . --config Release
MSBuild version 17.6.3+07e294721 for .NET Framework

  Checking Build System
  Building Custom Rule C:/Temp/CMakeLists.txt
  main.cpp
  tzdb_test.vcxproj -> C:\Temp\build\Release\tzdb_test.exe
  Building Custom Rule C:/Temp/CMakeLists.txt
PS C:\Temp\build> .\Release\tzdb_test.exe
America/New_York

Expected behavior

It is expected to not receive a std::runtime_error, thus crash if it's not caught, when using these functions.

STL version

Visual Studio version on compile VM:

Microsoft Visual Studio Community 2022 (64-bit) - Current
Version 17.6.2

Additional context

Problematic output is FAILURE: The specified module could not be found. This was not reproduced in the above output since the compile computer and the test computer are separate VMs.

@sylveon
Copy link
Contributor

sylveon commented Jul 9, 2023

We eventually discovered the ICU library which ships as part of the Windows 10 operating system in more recent versions (19H1 and after) and derives its data from the IANA database itself. As a result, updates to the time zone data will be executed along with updates to the OS through Windows Update. While our current implementation relies on the availability of the ICU DLL in more recent OS versions, we have plans to revisit the issue and investigate implementing a fallback for older operating systems. While there are a few discrepancies between the IANA database and the ICU library, the data should largely be the same.

https://devblogs.microsoft.com/cppblog/cpp20s-extensions-to-chrono-available-in-visual-studio-2019-version-16-10/

@lat9nq
Copy link
Author

lat9nq commented Jul 9, 2023

If this is a duplicate then my apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants