Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting durations #3662

Closed
Richardk2n opened this issue Sep 30, 2023 · 3 comments
Closed

Formatting durations #3662

Richardk2n opened this issue Sep 30, 2023 · 3 comments

Comments

@Richardk2n
Copy link
Contributor

https://godbolt.org/z/x5MfPr1KW
The doc says, that durations can be formatted.
However, it only specifies how 'q' 'Q' and 'j' behave (with 'j' not being implemented; see #3643)
If I format a duration of e.g., 25h with 'H' fmt::format gives 01 std::format gives 25
What is supposed to happen?

Also, the new durations added in C++ 20 are seemingly not implemented in fmt.

fmt and std also use different suffixes for minutes.

On a more general note I would like to add, that within this standard durations can be formatted as either basically a time or in the lowest unit used. However, both feel very unnatural. Usually one would write durations using several as large as possible units.

Would it be possible to give durations more options and a natural default format?

@vitaut
Copy link
Contributor

vitaut commented Oct 9, 2023

The definition of %H in the standard is a bit vague (https://eel.is/c++draft/time#tab:time.format.spec-row-15-column-2-sentence-1):

The hour (24-hour clock) as a decimal number.

but I think 01 is correct and libc++ which has a more complete std::format implementation agrees: https://godbolt.org/z/Kaco7brjM.

Also, the new durations added in C++ 20 are seemingly not implemented in fmt.
fmt and std also use different suffixes for minutes.

Thanks for fixing these.

Would it be possible to give durations more options and a natural default format?

Could you give an example illustrating what you mean by the natural format?

@Richardk2n
Copy link
Contributor Author

When formatting std::chrono::seconds(3700); for example from a time measurement or a calculated eta, a natural output for me would be 1h 1min 40s or even 1h 2min.

@vitaut
Copy link
Contributor

vitaut commented Oct 19, 2023

It is an intriguing idea but I don't think we need a format specifier for this. You can create a custom formatter instead.

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

No branches or pull requests

2 participants