@@ -1607,7 +1607,10 @@ namespace __format
format(const chrono::duration<_Rep, _Period>& __d,
basic_format_context<_Out, _CharT>& __fc) const
{
- return _M_f._M_format(chrono::abs(__d), __fc, __d < __d.zero());
+ if constexpr (numeric_limits<_Rep>::is_signed)
+ if (__d < __d.zero())
+ return _M_f._M_format(-__d, __fc, true);
+ return _M_f._M_format(__d, __fc, false);
}
private:
@@ -100,6 +100,12 @@ test_format()
std::chrono::duration<float, std::milli> d{0.5};
s = std::format("{}", d);
VERIFY( s == "0.5ms" );
+
+ std::chrono::duration<unsigned, std::milli> u{500}; // PR libstdc++/115668
+ s = std::format("{}", u);
+ VERIFY( s == "500ms" );
+ s = std::format("{:%Q %q}", u);
+ VERIFY( s == "500 ms" );
}
void