]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/time_point_cast/rounding.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / time_point_cast / rounding.cc
CommitLineData
8d9254fc 1// Copyright (C) 2016-2020 Free Software Foundation, Inc.
5f6acdfb
JW
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++11 } }
19
20// { dg-options "-std=gnu++17" }
21// { dg-do compile }
22
23#include <chrono>
24
25#if __cpp_lib_chrono < 201510
26# error "__cpp_lib_chrono < 201510"
27#endif
28
29using namespace std::chrono_literals;
30using std::chrono::seconds;
31using std::chrono::milliseconds;
32
33constexpr std::chrono::system_clock::time_point base{};
34
35static_assert( std::chrono::floor<seconds>(base + 1000ms) == (base + 1s) );
36static_assert( std::chrono::floor<seconds>(base + 1001ms) == (base + 1s) );
37static_assert( std::chrono::floor<seconds>(base + 1500ms) == (base + 1s) );
38static_assert( std::chrono::floor<seconds>(base + 1999ms) == (base + 1s) );
39static_assert( std::chrono::floor<seconds>(base + 2000ms) == (base + 2s) );
40static_assert( std::chrono::floor<seconds>(base + 2001ms) == (base + 2s) );
41static_assert( std::chrono::floor<seconds>(base + 2500ms) == (base + 2s) );
42
43static_assert( std::chrono::ceil<seconds>(base + 1000ms) == (base + 1s) );
44static_assert( std::chrono::ceil<seconds>(base + 1001ms) == (base + 2s) );
45static_assert( std::chrono::ceil<seconds>(base + 1500ms) == (base + 2s) );
46static_assert( std::chrono::ceil<seconds>(base + 1999ms) == (base + 2s) );
47static_assert( std::chrono::ceil<seconds>(base + 2000ms) == (base + 2s) );
48static_assert( std::chrono::ceil<seconds>(base + 2001ms) == (base + 3s) );
49static_assert( std::chrono::ceil<seconds>(base + 2500ms) == (base + 3s) );
50
51static_assert( std::chrono::round<seconds>(base + 1000ms) == (base + 1s) );
52static_assert( std::chrono::round<seconds>(base + 1001ms) == (base + 1s) );
53static_assert( std::chrono::round<seconds>(base + 1499ms) == (base + 1s) );
54static_assert( std::chrono::round<seconds>(base + 1500ms) == (base + 2s) );
55static_assert( std::chrono::round<seconds>(base + 1999ms) == (base + 2s) );
56static_assert( std::chrono::round<seconds>(base + 2000ms) == (base + 2s) );
57static_assert( std::chrono::round<seconds>(base + 2001ms) == (base + 2s) );
58static_assert( std::chrono::round<seconds>(base + 2500ms) == (base + 2s) );
59static_assert( std::chrono::round<seconds>(base + 2501ms) == (base + 3s) );