// { dg-do run { target c++20 } } // { dg-require-effective-target cxx11_abi } // { dg-timeout-factor 2 } #include #include #include void test_ostream() { using namespace std::chrono; std::stringstream ss; zoned_time zt("America/New_York", sys_seconds{946'706'523s}); ss << zt; VERIFY( ss.str() == "2000-01-01 01:02:03 EST" ); } void test_format() { using namespace std::chrono; sys_time t(1671470785708ms); auto zone = "America/New_York"; zoned_time zt(zone, t); // Every conversion specifier is valid for a sys_time except %q and %Q. std::string s = std::format("{:%a | %A | %b | %B | %c" " | %C | %d | %D | %e | %F | %g | %G | %h" " | %H | %I | %j | %m | %M | %p | %r | %R" " | %S | %T | %u | %U | %V | %w | %W | %x" " | %X | %y | %Y | %z | %Z}", zt); VERIFY( s == "Mon | Monday | Dec | December | Mon Dec 19 12:26:25 2022" " | 20 | 19 | 12/19/22 | 19 | 2022-12-19 | 22 | 2022 | Dec" " | 12 | 12 | 353 | 12 | 26 | PM | 12:26:25 PM | 12:26" " | 25.708 | 12:26:25.708 | 1 | 51 | 51 | 1 | 51 | 12/19/22" " | 12:26:25 | 22 | 2022 | -0500 | EST" ); std::wstring ws = std::format(L"{:%a | %A | %b | %B | %c" " | %C | %d | %D | %e | %F | %g | %G | %h" " | %H | %I | %j | %m | %M | %p | %r | %R" " | %S | %T | %u | %U | %V | %w | %W | %x" " | %X | %y | %Y | %z | %Z}", zt); VERIFY( ws == L"Mon | Monday | Dec | December | Mon Dec 19 12:26:25 2022" " | 20 | 19 | 12/19/22 | 19 | 2022-12-19 | 22 | 2022 | Dec" " | 12 | 12 | 353 | 12 | 26 | PM | 12:26:25 PM | 12:26" " | 25.708 | 12:26:25.708 | 1 | 51 | 51 | 1 | 51 | 12/19/22" " | 12:26:25 | 22 | 2022 | -0500 | EST" ); auto loc = std::locale::classic(); auto smod = std::format(loc, "{:%Ec %EC %Od %Oe %OH %OI %Om %OM %OS %Ou %OU" " %Ow %OW %Ex %EX %Oy %Ey %EY %Ez %Oz}", zt); s = std::format("{:%c %C %d %e %H %I %m %M %S %u %U" " %w %W %x %X %y %y %Y -05:00 -05:00}", zoned_time(zone, time_point_cast(t))); VERIFY( smod == s ); } int main() { test_ostream(); test_format(); }