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::time_zone::to_sys() on 'nonexistent time' deviates #113654

Open
chrisse74 opened this issue Oct 25, 2024 · 0 comments
Open

chrono::time_zone::to_sys() on 'nonexistent time' deviates #113654

chrisse74 opened this issue Oct 25, 2024 · 0 comments
Labels
chrono Issues related to std::chrono libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@chrisse74
Copy link

When calling the (experimental-library feature) std::chrono::time_zone::to_sys() with a 'nonexistent time' (daylight saving) the hour is corrected, but the minute part remains.

According to https://en.cppreference.com/w/cpp/chrono/time_zone/to_sys the correct behaviour would be: "If tp represents a nonexistent time between two UTC time_points, those two time_points will be the same, and that time_point will be returned."

Example

int main()
{
    using namespace std::literals;
    const std::chrono::time_zone* specificTimeZone = std::chrono::get_tzdb().locate_zone("Europe/Vienna");
    {
        const std::chrono::local_seconds inpTime{ std::chrono::local_days{ 2024y / std::chrono::March / 31d } + 2h + 0min };
        const std::chrono::sys_seconds experimentalSystemTimestamp = specificTimeZone->to_sys(inpTime, std::chrono::choose::earliest);
        std::cout << "UTC Timestamp: " << experimentalSystemTimestamp << std::endl;
    }

    {
        const std::chrono::local_seconds inpTime{ std::chrono::local_days{ 2024y / std::chrono::March / 31d } + 2h + 30min };
        const std::chrono::sys_seconds experimentalSystemTimestamp = specificTimeZone->to_sys(inpTime, std::chrono::choose::earliest);
        std::cout << "UTC Timestamp: " << experimentalSystemTimestamp << std::endl;
    }

    {
        const std::chrono::local_seconds inpTime{ std::chrono::local_days{ 2024y / std::chrono::March / 31d } + 3h + 0min };
        const std::chrono::sys_seconds experimentalSystemTimestamp = specificTimeZone->to_sys(inpTime, std::chrono::choose::earliest);
        std::cout << "UTC Timestamp: " << experimentalSystemTimestamp << std::endl;
    }

Output

UTC Timestamp: 2024-03-31 01:00:00
UTC Timestamp: 2024-03-31 01:30:00
UTC Timestamp: 2024-03-31 01:00:00

Expected output

I would expect all the local timestamps between 31.03.2024 02:00 and 3:00 being converted to the same UTC timestamp (2024-03-31 01:00:00).

Environment

  • clang version 19.1.2
  • compiled using -fexperimental-library
  • RHEL 9.4
@frederick-vs-ja frederick-vs-ja added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Oct 25, 2024
@EugeneZelenko EugeneZelenko added the chrono Issues related to std::chrono label Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chrono Issues related to std::chrono libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

3 participants