| 1 |
// { dg-do run { target c++20 } } |
| 2 |
|
| 3 |
// PR libstdc++/114240 sys_days not being parsed with only a date in the stream |
| 4 |
|
| 5 |
#include <chrono> |
| 6 |
#include <sstream> |
| 7 |
#include <testsuite_hooks.h> |
| 8 |
|
| 9 |
template<class Clock> |
| 10 |
void |
| 11 |
test_parse_date_only() |
| 12 |
{ |
| 13 |
using namespace std::chrono; |
| 14 |
|
| 15 |
using CDays = time_point<Clock, days>; |
| 16 |
CDays td; |
| 17 |
std::istringstream is("2024-03-05"); |
| 18 |
VERIFY( is >> parse("%Y-%m-%d ", td) ); |
| 19 |
if constexpr (std::is_same_v<Clock, std::chrono::local_t>) |
| 20 |
VERIFY( td == static_cast<local_time<days>>(2024y/March/5) ); |
| 21 |
else |
| 22 |
{ |
| 23 |
auto tp = clock_cast<Clock>(sys_days(2024y/March/5)); |
| 24 |
VERIFY( td == time_point_cast<days>(tp) ); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
int main() |
| 29 |
{ |
| 30 |
test_parse_date_only<std::chrono::system_clock>(); |
| 31 |
test_parse_date_only<std::chrono::utc_clock>(); |
| 32 |
test_parse_date_only<std::chrono::tai_clock>(); |
| 33 |
test_parse_date_only<std::chrono::gps_clock>(); |
| 34 |
test_parse_date_only<std::chrono::file_clock>(); |
| 35 |
test_parse_date_only<std::chrono::local_t>(); |
| 36 |
} |