Green Day Support
{fmt} doesn't support printing green day at the moment:
#include <fmt/chrono.h>
#include <fmt/color.h>
int main() {
fmt::print(fg(fmt::color::green), "{}", std::chrono::day());
}
Error:
include/fmt/core.h:1594:63: error: implicit instantiation of undefined template 'fmt::detail::type_is_unformattable_for<const std::chrono::day, char>'
type_is_unformattable_for<T, typename Context::char_type> _;
^
...
include/fmt/core.h:1597:3: error: static assertion failed due to requirement 'formattable': Cannot format an argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#udt
static_assert(
^
2 errors generated.
Looking at this, not only day(), but also month() and year(). It seems they do not have a formatter.
Adding a custom formatter does fix it, but should we support it? If we want to, where is the best place to define them?
The C++ standard mentions these formatters (https://eel.is/c++draft/time):
template<class charT> struct formatter<chrono::day, charT>;
template<class charT> struct formatter<chrono::month, charT>;
template<class charT> struct formatter<chrono::year, charT>;
in chrono.h, it defined the formatters for weekday, duration, time_point, etc., putting the defines for day, month, and year there works. I'll do some clean ups.
The C++ standard mentions these formatters (https://eel.is/c++draft/time):
template<class charT> struct formatter<chrono::day, charT>; template<class charT> struct formatter<chrono::month, charT>; template<class charT> struct formatter<chrono::year, charT>;
you're right, std should have those formatters, ~~but __cpp_lib_format is false, did some research, is it std::format not supported yet in MSVC?~~
It's interesting, as C++ 20 supports formatting all the chrono types, why you had to define the formatters for duration, weekday etc. in fmt in the first place? I think the issue is to make fmt make use the std::formatter's.
why you had to define the formatters for duration, weekday etc. in fmt in the first place? I think the issue is to make fmt make use the std::formatter's.
Good question. std::chrono is usually wider available than std::format and considering that day/month/year formatters should be easy to implement I think we should just do it ourselves.
Also year_month_day mentioned in #3772.
There are a couple more of interest.