| 1 |
// { dg-do run { target c++20 } } |
| 2 |
|
| 3 |
#include <chrono> |
| 4 |
#include <sstream> |
| 5 |
#include <testsuite_hooks.h> |
| 6 |
|
| 7 |
template<class Clock> |
| 8 |
void |
| 9 |
test_leap_second_parsing() |
| 10 |
{ |
| 11 |
std::chrono::time_point<Clock, std::chrono::milliseconds> tp, tp2; |
| 12 |
|
| 13 |
std::istringstream ss("20161231-23:59:60.05"); |
| 14 |
ss >> std::chrono::parse("%Y%m%d-%T", tp); |
| 15 |
|
| 16 |
if constexpr (std::is_same_v<Clock, std::chrono::local_t>) |
| 17 |
VERIFY( ss ); // We allow parsing "23:59:60" as local_time. |
| 18 |
else |
| 19 |
{ |
| 20 |
if constexpr (std::is_same_v<Clock, std::chrono::utc_clock>) |
| 21 |
{ |
| 22 |
// Entire input was consumed. |
| 23 |
VERIFY( ss ); |
| 24 |
VERIFY( ss.eof() ); |
| 25 |
// The parsed value is the leap second inserted on Jan 1 2017. |
| 26 |
VERIFY( std::chrono::get_leap_second_info(tp).is_leap_second ); |
| 27 |
} |
| 28 |
else |
| 29 |
VERIFY( !ss ); // Other clocks do not allow "HH:MM:60" |
| 30 |
|
| 31 |
ss.clear(); |
| 32 |
ss.str("20161231-22:59:60.05 -0100"); // Same time at -1h offset. |
| 33 |
ss >> std::chrono::parse("%Y%m%d-%T %z", tp2); |
| 34 |
|
| 35 |
if constexpr (std::is_same_v<Clock, std::chrono::utc_clock>) |
| 36 |
{ |
| 37 |
VERIFY( ss ); |
| 38 |
VERIFY( tp2 == tp ); |
| 39 |
} |
| 40 |
else |
| 41 |
VERIFY( !ss ); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
int main() |
| 46 |
{ |
| 47 |
test_leap_second_parsing<std::chrono::system_clock>(); |
| 48 |
test_leap_second_parsing<std::chrono::utc_clock>(); |
| 49 |
test_leap_second_parsing<std::chrono::tai_clock>(); |
| 50 |
test_leap_second_parsing<std::chrono::gps_clock>(); |
| 51 |
test_leap_second_parsing<std::chrono::file_clock>(); |
| 52 |
test_leap_second_parsing<std::chrono::local_t>(); |
| 53 |
} |