Skip to content

<chrono>: system_clock::now() and file_clock::from_utc() interpret FILETIME in different ways #1822

@statementreply

Description

@statementreply

Describe the bug
In old Windows versions, FILETIME didn't count leap seconds. Since Windows 10 1809, Windows has become aware of leap seconds, and FILETIME counts leap seconds after 2018-06 by default (could be turned off system-wide to restore the old behavior).

Currently, system_clock::now() assumes the old behavior that FILETIME doesn't count leap seconds (#1520):

STL/stl/inc/chrono

Lines 666 to 668 in 4ee3f91

_NODISCARD static time_point now() noexcept { // get current time
return time_point(duration(_Xtime_get_ticks()));
}

But file_clock::from_utc() and file_clock::to_utc() assume that FILETIME always counts leap seconds after 2017:

STL/stl/inc/chrono

Lines 3324 to 3325 in 4ee3f91

// Assumes that FILETIME counts leap seconds only after the first 27 (i.e., after 1 January 2017), even though
// systems can opt out of this behavior.

We should fix all of them to return the correct result whether or not the system is leap second aware.

STL version
4ee3f91

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingchronoC++20 chrono

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions