Skip to content

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

Description

@ecorm

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions