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

Arbitrary sys_time<Duration> types are not formattable out of the box #2208

Closed
ecorm opened this issue Apr 1, 2021 · 1 comment
Closed

Comments

@ecorm
Copy link

ecorm commented Apr 1, 2021

When attempting to format a std::chrono::sys_time<Duration>, where Duration is not the same as std::chrono::system_clock::duration, compilation fails with the static assertion:

static_assert failed due to requirement '!std::is_same<const fmt::v7::detail::unformattable &, const fmt::v7::detail::unformattable &>::value' "Cannot format an argument. To make type T formattable provide a formatter specialization

Godbolt demo: https://godbolt.org/z/7Moc5cKrr

According to https://en.cppreference.com/w/cpp/chrono/system_clock/formatter, C++20's format accepts any duration type for sys_time.

hinnant/date's format accepts any arbitrary sys_time:

using time_type =
    std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>;
time_type t{std::chrono::seconds{42}};
auto s = date::format(std::locale::classic(), "%S", t);
std::cout << s << "\n"; // prints 42

This is related to issue #2207 where one would want to std::chrono::floor a sys_time to the desired precision for formatting.

@vitaut
Copy link
Contributor

vitaut commented Apr 2, 2021

Added support for time points with arbitrary durations in 06b3a10. Thanks for reporting.

@vitaut vitaut closed this as completed Apr 2, 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

2 participants