
This adds the operator<< overloads and std::formatter specializations required by C++20 so that <chrono> types can be written to ostreams and printed with std::format. libstdc++-v3/ChangeLog: * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/std/chrono (operator<<): Move to new header. (nonexistent_local_time::_M_make_what_str): Define correctly. (ambiguous_local_time::_M_make_what_str): Likewise. * include/bits/chrono_io.h: New file. * src/c++20/tzdb.cc (operator<<(ostream&, const Rule&)): Use new ostream output for month and weekday types. * testsuite/20_util/duration/io.cc: Test std::format support. * testsuite/std/time/exceptions.cc: Check what() strings. * testsuite/std/time/syn_c++20.cc: Uncomment local_time_format. * testsuite/std/time/time_zone/get_info_local.cc: Enable check for formatted output of local_info objects. * testsuite/std/time/clock/file/io.cc: New test. * testsuite/std/time/clock/gps/io.cc: New test. * testsuite/std/time/clock/system/io.cc: New test. * testsuite/std/time/clock/tai/io.cc: New test. * testsuite/std/time/clock/utc/io.cc: New test. * testsuite/std/time/day/io.cc: New test. * testsuite/std/time/format.cc: New test. * testsuite/std/time/hh_mm_ss/io.cc: New test. * testsuite/std/time/month/io.cc: New test. * testsuite/std/time/weekday/io.cc: New test. * testsuite/std/time/year/io.cc: New test. * testsuite/std/time/year_month_day/io.cc: New test.
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
// { dg-options "-std=gnu++20" }
|
|
// { dg-do run { target c++20 } }
|
|
// { dg-require-effective-target tzdb }
|
|
|
|
#include <chrono>
|
|
#include <testsuite_hooks.h>
|
|
|
|
void
|
|
test_nonexistent()
|
|
{
|
|
std::string expected
|
|
= "2016-03-13 02:30:00 is in a gap between\n"
|
|
"2016-03-13 02:00:00 EST and\n"
|
|
"2016-03-13 03:00:00 EDT which are both equivalent to\n"
|
|
"2016-03-13 07:00:00 UTC";
|
|
|
|
using namespace std::chrono;
|
|
try {
|
|
auto zt = zoned_time{"America/New_York",
|
|
local_days{Sunday[2]/March/2016} + 2h + 30min};
|
|
VERIFY(false);
|
|
} catch (const nonexistent_local_time& e) {
|
|
VERIFY( e.what() == expected );
|
|
}
|
|
}
|
|
|
|
void
|
|
test_ambiguous()
|
|
{
|
|
std::string expected
|
|
= "2016-11-06 01:30:00 is ambiguous. It could be\n"
|
|
"2016-11-06 01:30:00 EDT == 2016-11-06 05:30:00 UTC or\n"
|
|
"2016-11-06 01:30:00 EST == 2016-11-06 06:30:00 UTC";
|
|
|
|
using namespace std::chrono;
|
|
try {
|
|
auto zt = zoned_time{"America/New_York",
|
|
local_days{Sunday[1]/November/2016} + 1h + 30min};
|
|
VERIFY(false);
|
|
} catch (const ambiguous_local_time& e) {
|
|
VERIFY( e.what() == expected );
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
test_nonexistent();
|
|
test_ambiguous();
|
|
}
|