Index: libcxx/include/__chrono/formatter.h =================================================================== --- libcxx/include/__chrono/formatter.h +++ libcxx/include/__chrono/formatter.h @@ -85,7 +85,8 @@ using __duration = chrono::duration<_Rep, _Period>; - auto __fraction = __value - chrono::duration_cast(__value); + constexpr auto __one_sec = chrono::duration_cast(chrono::seconds(1u)); + auto __micro_seconds = chrono::duration_cast(__value).count() % __one_sec.count(); if constexpr (chrono::treat_as_floating_point_v<_Rep>) // When the floating-point value has digits itself they are ignored based // on the wording in [tab:time.format.spec] @@ -100,13 +101,13 @@ // differently and uses 3 decimals. // https://godbolt.org/z/6dsbnW8ba std::format_to(std::ostreambuf_iterator<_CharT>{__sstr}, - _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"), - __fraction.count(), + _LIBCPP_STATICALLY_WIDEN(_CharT, "{:{}.0f}"), + __micro_seconds, chrono::hh_mm_ss<__duration>::fractional_width); else std::format_to(std::ostreambuf_iterator<_CharT>{__sstr}, - _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}}"), - __fraction.count(), + _LIBCPP_STATICALLY_WIDEN(_CharT, "{:0<{}}"), + __micro_seconds, chrono::hh_mm_ss<__duration>::fractional_width); }