| 1 |
// { dg-do run { target c++20 } } |
| 2 |
|
| 3 |
#include <chrono> |
| 4 |
#include <format> |
| 5 |
#include <locale> |
| 6 |
#include <testsuite_hooks.h> |
| 7 |
|
| 8 |
struct custom_time_put : std::time_put<char> |
| 9 |
{ |
| 10 |
iter_type |
| 11 |
do_put(iter_type out, std::ios_base& io, char_type fill, const tm* t, |
| 12 |
char format, char modifier) const override |
| 13 |
{ |
| 14 |
using Base = std::time_put<char>; |
| 15 |
|
| 16 |
switch (format) { |
| 17 |
case 'a': case 'A': case 'b': case 'B': case 'p': |
| 18 |
*out++ = '['; |
| 19 |
*out++ = format; |
| 20 |
*out++ = ']'; |
| 21 |
} |
| 22 |
return Base::do_put(out, io, fill, t, format, modifier); |
| 23 |
} |
| 24 |
}; |
| 25 |
|
| 26 |
int main() |
| 27 |
{ |
| 28 |
using namespace std::chrono; |
| 29 |
std::locale loc(std::locale::classic(), new custom_time_put); |
| 30 |
#define test(t, fmt, exp) VERIFY( std::format(loc, fmt, t) == exp ) |
| 31 |
test(Monday, "{:L%a}", "[a]Mon"); |
| 32 |
test(Monday, "{:L%A}", "[A]Monday"); |
| 33 |
test(January, "{:L%b}", "[b]Jan"); |
| 34 |
test(January, "{:L%B}", "[B]January"); |
| 35 |
test(1h, "{:L%p}", "[p]AM"); |
| 36 |
} |