Make std::chrono::duration formatting more similar to C++20 standard #2554
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
Currently std::chrono::duration with the
%S
and%T
specifiers is not printed according to the spec. This issue was addressed but later dropped in #2207. Many commits have appeared since then so I have tried to implement a new approach.Now, the
%S
specifier only prints with millisecond precision. I have implemented the subsecond extractor, inspired by the MSVC STL implementation of std::format for the hh_mm_ss class. Please see the new unit tests.Further comments:
%T
specifier now behaves according to the C++20 standard and should be equivalent to%H:%M:%S
subsecond_helper
functions. Not sure iffmt_safe_duration_cast
is required and more analysis might be needed.std::chrono::duration::period
tostd::uintmax_t
, this behavior is probably acceptable according to the spec as it only requires the value to be as precise as the thestd::ratio
instd::chrono::duration::period
. The MSVC implementation usesstd::floor
Comments and suggestions are welcome.
Thanks