Skip to content

Keep subseconds when formatting durations with %OS - #5019

Open
chinmayajha wants to merge 1 commit into
fmtlib:mainfrom
chinmayajha:duration-os-subseconds
Open

chinmayajha wants to merge 1 commit into
fmtlib:mainfrom
chinmayajha:duration-os-subseconds

Conversation

@chinmayajha

Copy link
Copy Markdown

%OS drops sub-seconds when formatting a duration: fmt::format("{:%OS}", std::chrono::milliseconds(1234)) gives 01, while {:%S} gives 01.234. In the classic locale the alternative representation is the same as the standard one, and libc++'s std::format prints 01.234 for both.

The time_point formatter already handles this: tm_writer::on_second uses the standard path when the locale is classic. This uses the same condition in duration_formatter::on_second. With L and a non-classic locale it still goes through the locale's %OS without sub-seconds, same as for time points.

The new test fails before the change and the full test suite passes. It is independent of #5018.

@chinmayajha
chinmayajha requested a review from vitaut as a code owner November 6, 2026 22:19
@chinmayajha
chinmayajha force-pushed the duration-os-subseconds branch from a84fc85 to 4acf78d Compare November 8, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant