std::chrono and missing (?) support for negative leap seconds

430 Views Asked by At

C++20 added time zone support to std::chrono, and this includes leap seconds. However, it appears as if only leap second insertion was supported, not leap second removal, that is, negative leap seconds. (Admittedly, since 1972 there only have been positive leap seconds; but it seems that in the last few years the drift has reversed, and a negative leap second seems possible in the upcoming years.)

This is evident from the way the std::chrono::leap_second class is described - there's no way to tell positive from negative leap seconds.

Is it known why std::chrono doesn't support this possibility? Was this an optimization, or a mistake of some sort? Or is it supported already and I have missed something?

Note: The MSVC implementation seems to have a nonstandard feature that allows negative leap seconds.

1

There are 1 best solutions below

4
On BEST ANSWER

[time.zone.leap.members]/2 actually does specify negative leap seconds.

Returns: +1s to indicate a positive leap second or -1s to indicate a negative leap second. [Note 1: All leap seconds inserted up through 2019 were positive leap seconds. — end note]

When the standard speaks of insertion of a leap second, that leap second could be negative, which would be the same as a removal.

Note: I am unsure if this is new to C++23 or also in C++20, I don't have a copy of the C++20 draft with me right now.