-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
std::chrono duration formatting is lacking floating point specifiers #1004
Comments
I've implemented some stuff to handle the precision specification, but this is probably a dead end. |
Here is one way to address this:
|
Right, in this case (static precision, static formatting string), the workaround of shifting the precision part of the formatting process onto the user certainly works. In the general case it doesn't and maintenance in non-trivial codebases with the prospect of engineering changes might become a nightmare. After all, {fmt}'s added value and most noble goal is relieving users from the burden of formatting. |
Supporting precision for duration types with floating-point representation makes a lot of sense to me.
@DanielaE why do you think so? |
Well, I am not sure about the direction of the implementation of this feature. I am glad that you support the idea. My experimental stuff does a consistent parsing so far, but it's totally unclear to me on how to proceed from there. I've learned from Howards comment that backing the formatting process on chrono's output streaming operator is not the way to go in this case. Currently I envision an implementation which checks the formatting string for |
p1361r0 proposes support for fill, width, and alignment before the main strftime-like specifiers:
We could easily incorporate precision there:
|
This makes lots of sense to me. I like it a lot. I've been studying the current state of |
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
@vitaut Any opinion on DanielaE@f859515 before I open a PR? In this implementation, the precision applies to the numeric formatting in absence of |
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
DanielaE@7571832 is a bit more refined with some preparation for |
Looks good to me. Please open a PR and I'll comment there with some minor suggestions. |
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
done |
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in fmtlib#1004. Signed-off-by: Daniela Engert <[email protected]>
The formatting syntax follows p1361r0, augmented by a precision field as proposed in #1004. Signed-off-by: Daniela Engert <[email protected]>
Expect a follow-up to keep track with Howard's |
@HowardHinnant, where would you put the precision specifier into the |
I'm really not sure, but am guessing something like |
Thinking about it, this is a bit underspecified so far imho in case of multiple |
Seems reasonable. |
Howard Hinnant's 'date' library recently gained these two new formatting specifiers. This implementation in {fmt} includes support for 'std::chrono::duration' specializations with floating-point representation types and user-definable precision. Signed-off-by: Daniela Engert <[email protected]>
Is implemented now - enjoy 😄 |
I guess this issue can be closed now. |
Consider this test code:
The first and second test passes, i.e. floating point representation types in
std::chrono::duration
work in general. The last fails by returning.2
rather than formatting the given time quantity of 1.2345 ms to the given precision. There is seemingly no application of floating point specifiers possible.The text was updated successfully, but these errors were encountered: