Skip to content

Commit

Permalink
Fix subseconds on leap second
Browse files Browse the repository at this point in the history
  • Loading branch information
eldakesh-ms committed Apr 20, 2021
1 parent bd8e675 commit d433ff7
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -5465,28 +5465,33 @@ namespace chrono {
_STL_INTERNAL_CHECK(false);
}

template <class _CharT, class _Traits, class _Duration>
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const hh_mm_ss<_Duration>& _Val) {
_Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:02}"), _Val.seconds().count());
if constexpr (hh_mm_ss<_Duration>::fractional_width > 0) {
template <unsigned int _Fractional_width, class _CharT, class _Traits, class _Precision>
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const seconds& _Seconds, const _Precision& _Subseconds) {
_Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:02}"), _Seconds.count());
if constexpr (_Fractional_width > 0) {
_Os << _STD use_facet<numpunct<_CharT>>(_Os.getloc()).decimal_point();
if constexpr (treat_as_floating_point_v<typename hh_mm_ss<_Duration>::precision::rep>) {
_Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"), _STD floor(_Val.subseconds().count()),
_Val.fractional_width);
} else {
if constexpr (treat_as_floating_point_v<_Precision::rep>) {
_Os << _STD format(
_STATICALLY_WIDEN(_CharT, "{:0{}}"), _Val.subseconds().count(), _Val.fractional_width);
_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"), _STD floor(_Subseconds.count()), _Fractional_width);
} else {
_Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:0{}}"), _Subseconds.count(), _Fractional_width);
}
}
}

template <class _CharT, class _Traits, class _Duration>
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const hh_mm_ss<_Duration>& _Val) {
_Write_seconds<_Val.fractional_width>(_Os, _Val.seconds(), _Val.subseconds());
}

template <class _CharT, class _Traits, class _Clock, class _Duration>
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const time_point<_Clock, _Duration>& _Val) {
if constexpr (is_same_v<_Clock, utc_clock>) {
const auto _Dp = _CHRONO floor<days>(_Val) + get_leap_second_info(_Val).elapsed;
const auto _Hms = hh_mm_ss{_Val - _Dp};
if (_CHRONO get_leap_second_info(_Val).is_leap_second) {
_Os << _STATICALLY_WIDEN(_CharT, "60");
_Write_seconds<_Hms.fractional_width>(_Os, _Hms.seconds() + 60s, _Hms.subseconds());
} else {
const auto _Dp = _CHRONO floor<days>(_Val) + get_leap_second_info(_Val).elapsed;
_Write_seconds(_Os, hh_mm_ss{_Val - _Dp});
}
return;
Expand Down

0 comments on commit d433ff7

Please sign in to comment.