A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/fmtlib/fmt/issues/4350 below:

It's possible to get an exception when working with localised times · Issue #4350 · fmtlib/fmt · GitHub

Environment:
Windows 10 x64
MSVC Version 17.12.4

It;'s possible to pass a std::chrono::local_seconds object to format that has an ambiguous time, so for example ~2am on April 6th 2025 in Sydney daylight savings ends.

Sample Code (note, system running must be on AEDT)

#include <chrono>
#include <cstdlib>
#include <iostream>
#include <fmt/core.h>
#include <fmt/chrono.h>

int main()
{
    const auto& timeZoneDatabase = std::chrono::get_tzdb();
    const auto& currentZone = timeZoneDatabase.current_zone();
    std::cout << currentZone->name() << '\n'; // This needs to be Australia/Sydney

    uint64_t two_in_the_morning = 1743865205; // just after 2am on 2025/4/6 which is a daylight savings changeover point
    auto dur = std::chrono::duration<uint64_t>(two_in_the_morning);
    auto time_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<uint64_t>>(dur);
    auto time_point_as_local_seconds = currentZone->to_local(std::chrono::floor<std::chrono::seconds>(time_point));

    std::string text = fmt::format("{:%Y-%m-%d %H:%M:%S}", time_point_as_local_seconds);
    std::cout << text << '\n';
    return 0;
}

This block here seems to be the cause:

template <typename Duration, FMT_ENABLE_IF(detail::has_current_zone<Duration>())> inline auto localtime(std::chrono::local_time<Duration> time) -> std::tm { using namespace std::chrono; using namespace fmt_detail; return localtime(detail::to_time_t(current_zone()->to_sys<Duration>(time)));

to_sys can throw exceptions in these cases, and needs to be passed std::chrono::choose


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4