| 1 | // Copyright (C) 2016-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 compile { target c++17 } } |
| 19 | // { dg-add-options no_pch } |
| 20 | |
| 21 | #include <chrono> |
| 22 | |
| 23 | #if __cpp_lib_chrono < 201510 |
| 24 | # error "__cpp_lib_chrono < 201510" |
| 25 | #endif |
| 26 | |
| 27 | using namespace std::chrono_literals; |
| 28 | using std::chrono::seconds; |
| 29 | using std::chrono::milliseconds; |
| 30 | |
| 31 | constexpr std::chrono::system_clock::time_point base{}; |
| 32 | |
| 33 | static_assert( std::chrono::floor<seconds>(base + 1000ms) == (base + 1s) ); |
| 34 | static_assert( std::chrono::floor<seconds>(base + 1001ms) == (base + 1s) ); |
| 35 | static_assert( std::chrono::floor<seconds>(base + 1500ms) == (base + 1s) ); |
| 36 | static_assert( std::chrono::floor<seconds>(base + 1999ms) == (base + 1s) ); |
| 37 | static_assert( std::chrono::floor<seconds>(base + 2000ms) == (base + 2s) ); |
| 38 | static_assert( std::chrono::floor<seconds>(base + 2001ms) == (base + 2s) ); |
| 39 | static_assert( std::chrono::floor<seconds>(base + 2500ms) == (base + 2s) ); |
| 40 | |
| 41 | static_assert( std::chrono::ceil<seconds>(base + 1000ms) == (base + 1s) ); |
| 42 | static_assert( std::chrono::ceil<seconds>(base + 1001ms) == (base + 2s) ); |
| 43 | static_assert( std::chrono::ceil<seconds>(base + 1500ms) == (base + 2s) ); |
| 44 | static_assert( std::chrono::ceil<seconds>(base + 1999ms) == (base + 2s) ); |
| 45 | static_assert( std::chrono::ceil<seconds>(base + 2000ms) == (base + 2s) ); |
| 46 | static_assert( std::chrono::ceil<seconds>(base + 2001ms) == (base + 3s) ); |
| 47 | static_assert( std::chrono::ceil<seconds>(base + 2500ms) == (base + 3s) ); |
| 48 | |
| 49 | static_assert( std::chrono::round<seconds>(base + 1000ms) == (base + 1s) ); |
| 50 | static_assert( std::chrono::round<seconds>(base + 1001ms) == (base + 1s) ); |
| 51 | static_assert( std::chrono::round<seconds>(base + 1499ms) == (base + 1s) ); |
| 52 | static_assert( std::chrono::round<seconds>(base + 1500ms) == (base + 2s) ); |
| 53 | static_assert( std::chrono::round<seconds>(base + 1999ms) == (base + 2s) ); |
| 54 | static_assert( std::chrono::round<seconds>(base + 2000ms) == (base + 2s) ); |
| 55 | static_assert( std::chrono::round<seconds>(base + 2001ms) == (base + 2s) ); |
| 56 | static_assert( std::chrono::round<seconds>(base + 2500ms) == (base + 2s) ); |
| 57 | static_assert( std::chrono::round<seconds>(base + 2501ms) == (base + 3s) ); |