| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do run { target c++20 } } |
| 19 |
|
| 20 |
#include <chrono> |
| 21 |
#include <testsuite_hooks.h> |
| 22 |
|
| 23 |
void |
| 24 |
test01() |
| 25 |
{ |
| 26 |
auto sys_now = std::chrono::system_clock::now(); |
| 27 |
auto file_now = std::chrono::file_clock::now(); |
| 28 |
auto d1 = std::chrono::file_clock::to_sys(file_now) - sys_now; |
| 29 |
VERIFY( d1 < std::chrono::seconds(1) ); |
| 30 |
auto d2 = file_now - std::chrono::file_clock::from_sys(sys_now); |
| 31 |
VERIFY( d2 == d1 ); |
| 32 |
} |
| 33 |
|
| 34 |
void |
| 35 |
test02() |
| 36 |
{ |
| 37 |
using namespace std::chrono; |
| 38 |
|
| 39 |
file_time<file_clock::duration> t = file_clock::now(); |
| 40 |
file_time<seconds> s = floor<seconds>(t); |
| 41 |
VERIFY( t - s < 1s ); |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
test03() |
| 46 |
{ |
| 47 |
using namespace std::chrono; |
| 48 |
auto st = sys_days(2024y/January/21); |
| 49 |
VERIFY( file_clock::to_sys(file_clock::from_sys(st)) == st ); |
| 50 |
} |
| 51 |
|
| 52 |
int |
| 53 |
main() |
| 54 |
{ |
| 55 |
test01(); |
| 56 |
test02(); |
| 57 |
test03(); |
| 58 |
} |