Skip to content

<chrono>: Time zone Africa/Juba causes runtime_error in std::chrono::tzdb::current_zone #3854

@lat9nq

Description

@lat9nq

Describe the bug

A user can choose the time zone Africa/Juba in Windows 10 by selecting (UTC+02:00) Juba in the Date & Time options. This time zone has a path and name, however causes a runtime_error if used here.

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
FAILURE: unable to locate time_zone with given name

Expected behavior

It is expected to not receive a std::runtime_error, thus crash if it's not caught, when using these functions. Instead, this program should output the string Africa/Juba.

STL version

Visual Studio version on compile VM:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    chronoC++20 chronoexternalThis issue is unrelated to the STL

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions