Skip to content

Commit d433ff7

Browse files
committed
Fix subseconds on leap second
1 parent bd8e675 commit d433ff7

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

stl/inc/chrono

+16-11
Original file line numberDiff line numberDiff line change
@@ -5465,28 +5465,33 @@ namespace chrono {
54655465
_STL_INTERNAL_CHECK(false);
54665466
}
54675467

5468-
template <class _CharT, class _Traits, class _Duration>
5469-
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const hh_mm_ss<_Duration>& _Val) {
5470-
_Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:02}"), _Val.seconds().count());
5471-
if constexpr (hh_mm_ss<_Duration>::fractional_width > 0) {
5468+
template <unsigned int _Fractional_width, class _CharT, class _Traits, class _Precision>
5469+
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const seconds& _Seconds, const _Precision& _Subseconds) {
5470+
_Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:02}"), _Seconds.count());
5471+
if constexpr (_Fractional_width > 0) {
54725472
_Os << _STD use_facet<numpunct<_CharT>>(_Os.getloc()).decimal_point();
5473-
if constexpr (treat_as_floating_point_v<typename hh_mm_ss<_Duration>::precision::rep>) {
5474-
_Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"), _STD floor(_Val.subseconds().count()),
5475-
_Val.fractional_width);
5476-
} else {
5473+
if constexpr (treat_as_floating_point_v<_Precision::rep>) {
54775474
_Os << _STD format(
5478-
_STATICALLY_WIDEN(_CharT, "{:0{}}"), _Val.subseconds().count(), _Val.fractional_width);
5475+
_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"), _STD floor(_Subseconds.count()), _Fractional_width);
5476+
} else {
5477+
_Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:0{}}"), _Subseconds.count(), _Fractional_width);
54795478
}
54805479
}
54815480
}
54825481

5482+
template <class _CharT, class _Traits, class _Duration>
5483+
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const hh_mm_ss<_Duration>& _Val) {
5484+
_Write_seconds<_Val.fractional_width>(_Os, _Val.seconds(), _Val.subseconds());
5485+
}
5486+
54835487
template <class _CharT, class _Traits, class _Clock, class _Duration>
54845488
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const time_point<_Clock, _Duration>& _Val) {
54855489
if constexpr (is_same_v<_Clock, utc_clock>) {
5490+
const auto _Dp = _CHRONO floor<days>(_Val) + get_leap_second_info(_Val).elapsed;
5491+
const auto _Hms = hh_mm_ss{_Val - _Dp};
54865492
if (_CHRONO get_leap_second_info(_Val).is_leap_second) {
5487-
_Os << _STATICALLY_WIDEN(_CharT, "60");
5493+
_Write_seconds<_Hms.fractional_width>(_Os, _Hms.seconds() + 60s, _Hms.subseconds());
54885494
} else {
5489-
const auto _Dp = _CHRONO floor<days>(_Val) + get_leap_second_info(_Val).elapsed;
54905495
_Write_seconds(_Os, hh_mm_ss{_Val - _Dp});
54915496
}
54925497
return;

0 commit comments

Comments
 (0)