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

Default format prints nothing for std::chrono::system_clock::time_point #2319

Closed
toomuchsalt opened this issue May 28, 2021 · 4 comments
Closed

Comments

@toomuchsalt
Copy link

Tested with both current head and version 7.1.3( godbolt )

The following code yields an empty string

#include <fmt/chrono.h>

#include <chrono>

int main() {
  fmt::print("Default format: {} ", std::chrono::system_clock::now());
}

https://godbolt.org/z/E33jW916o

@vitaut
Copy link
Contributor

vitaut commented May 28, 2021

Looks like the default format should be as described in https://eel.is/c++draft/time#clock.system.nonmembers-2, but this is not implemented yet. PRs are welcome.

@sunmy2019
Copy link
Contributor

This part is a little bit triky.
In the C++ stardard, we need a locale object to format year_month_day and hh_mm_ss. Thus, directly using fmt::print lacks the information of which locale to use.
Even with fmt::format(locale, format, args), there is a problem: we cannot squeeze the date/time format direcly from locale (unless we use some internal API). So a call to the time_put is inevitable if we stick to the standard.

There are some workarounds.

  1. We can throw away the locale object, using {:%Y-%m-%d %H:%M:%S} as default format.
  2. We can keep the locale object, and use the global locale if unsepecified. Making every output go through the function time_put. Just like the how we handle weekday's format.

The first is easy to implement. (I already implemented.) While the latter is more complicated, and of course, more time/memory consuming.

@vitaut
Copy link
Contributor

vitaut commented Jun 7, 2021

The default should be locale-independent (the first option). There is a Library Working Group issue to fix it in the standard as well.

@vitaut
Copy link
Contributor

vitaut commented Jun 12, 2021

Default format has been added in #2345. Thanks @sunmy2019.

@vitaut vitaut closed this as completed Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants