// { dg-do run { target c++20 } } #include #include #include #include struct custom_time_put : std::time_put { iter_type do_put(iter_type out, std::ios_base& io, char_type fill, const tm* t, char format, char modifier) const override { using Base = std::time_put; switch (format) { case 'a': case 'A': case 'b': case 'B': case 'p': *out++ = '['; *out++ = format; *out++ = ']'; } return Base::do_put(out, io, fill, t, format, modifier); } }; int main() { using namespace std::chrono; std::locale loc(std::locale::classic(), new custom_time_put); #define test(t, fmt, exp) VERIFY( std::format(loc, fmt, t) == exp ) test(Monday, "{:L%a}", "[a]Mon"); test(Monday, "{:L%A}", "[A]Monday"); test(January, "{:L%b}", "[b]Jan"); test(January, "{:L%B}", "[B]January"); test(1h, "{:L%p}", "[p]AM"); }