gcc/libstdc++-v3/testsuite/std/time/zoned_time/io.cc
Jonathan Wakely 7d06b29f81 libstdc++: Add dg-timeout-factor to <chrono> IO tests
This avoids failures due to compilation timeouts when testing with a low
tool_timeout value.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/duration/io.cc: Double timeout using
	dg-timeout-factor.
	* testsuite/std/time/day/io.cc: Likewise.
	* testsuite/std/time/format.cc: Likewise.
	* testsuite/std/time/hh_mm_ss/io.cc: Likewise.
	* testsuite/std/time/month/io.cc: Likewise.
	* testsuite/std/time/month_day/io.cc: Likewise.
	* testsuite/std/time/month_day_last/io.cc: Likewise.
	* testsuite/std/time/month_weekday/io.cc: Likewise.
	* testsuite/std/time/month_weekday_last/io.cc: Likewise.
	* testsuite/std/time/weekday/io.cc: Likewise.
	* testsuite/std/time/weekday_indexed/io.cc: Likewise.
	* testsuite/std/time/weekday_last/io.cc: Likewise.
	* testsuite/std/time/year/io.cc: Likewise.
	* testsuite/std/time/year_month/io.cc: Likewise.
	* testsuite/std/time/year_month_day/io.cc: Likewise.
	* testsuite/std/time/year_month_day_last/io.cc: Likewise.
	* testsuite/std/time/year_month_weekday/io.cc: Likewise.
	* testsuite/std/time/year_month_weekday_last/io.cc: Likewise.
	* testsuite/std/time/zoned_time/io.cc: Likewise.
2023-10-26 21:10:47 +01:00

64 lines
2.1 KiB
C++

// { dg-do run { target c++20 } }
// { dg-require-effective-target cxx11_abi }
// { dg-timeout-factor 2 }
#include <chrono>
#include <sstream>
#include <testsuite_hooks.h>
void
test_ostream()
{
using namespace std::chrono;
std::stringstream ss;
zoned_time<seconds> 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<milliseconds> t(1671470785708ms);
auto zone = "America/New_York";
zoned_time<milliseconds> 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<seconds>(zone, time_point_cast<seconds>(t)));
VERIFY( smod == s );
}
int main()
{
test_ostream();
test_format();
}