-
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::utc_timestamp is not formattable via fmt/chrono.h #3098
Comments
A PR to add a formatter for |
After having a closer look on the topic: It's pretty easy and straight forward to add a formatter for The bad news is that this doesn't help for our project because we need the nanosecond accuracy, i.e., something like "2022-09-12 12:57:14.844838800" (as After looking through the details of My idea to implement this would be roughly:
And then the problems begin... it seems that everything is pretty optimized for "classic dates" without nanoseconds (e.g. What do you think, is this the right approach? Or shouldn't we use the |
In general sounds reasonable. I would suggest splitting this into multiple PRs, first to add the formatter specialization, then adding nanosecond support. |
Added a PR for the formatter. The request for fractional second accuracy is more or less a duplicate of #2207 I hope I find some time in the next week to work on this issue. |
Closing since |
With C++20 we can format all the
std::chrono
types usingstd::format
, e.g., the following programcompiles and gives the output "2022-09-12 12:57:14.844838800".
So I would expect that this works also for
fmt::format
, at least if I include fmt/chrono.h or maybe also fmt/std.h. But the following programdoesn't compile with the current fmt master (94ceb38). We get
error C2338: static_assert failed: 'Cannot format an argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#udt'
.I'm using the following work-around now to get the above program compiling:
I.e., I provide a custom formatter which does nothing else than forwarding the UTC timestamp to
std::format
. This works fine, but somehow feels unsatisfying. We doesn't provide fmt a formatter for a std::chrono UTC timestamp, even it is supported bystd::format
? Is this really intended or was this forgotten?The text was updated successfully, but these errors were encountered: