1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
14 // template <class ToDuration, class Rep, class Period>
17 // ceil(const duration<Rep, Period>& d);
20 #include <type_traits>
23 #include "test_macros.h"
25 template <class ToDuration
, class FromDuration
>
27 test(const FromDuration
& f
, const ToDuration
& d
)
30 typedef decltype(std::chrono::round
<ToDuration
>(f
)) R
;
31 static_assert((std::is_same
<R
, ToDuration
>::value
), "");
32 assert(std::chrono::round
<ToDuration
>(f
) == d
);
38 // 7290000ms is 2 hours, 1 minute, and 30 seconds
39 test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2));
40 test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2));
41 test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122));
42 test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122));
45 // 9000000ms is 2 hours and 30 minutes
46 constexpr std::chrono::hours h1
= std::chrono::round
<std::chrono::hours
>(std::chrono::milliseconds(9000000));
47 static_assert(h1
.count() == 2, "");
48 constexpr std::chrono::hours h2
= std::chrono::round
<std::chrono::hours
>(std::chrono::milliseconds(-9000000));
49 static_assert(h2
.count() == -2, "");