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
15 // template <class ToDuration, class Rep, class Period>
18 // ceil(const duration<Rep, Period>& d);
21 #include <type_traits>
24 #include "test_macros.h"
26 template <class ToDuration
, class FromDuration
>
28 test(const FromDuration
& f
, const ToDuration
& d
)
31 typedef decltype(std::chrono::ceil
<ToDuration
>(f
)) R
;
32 static_assert((std::is_same
<R
, ToDuration
>::value
), "");
33 assert(std::chrono::ceil
<ToDuration
>(f
) == d
);
39 // 7290000ms is 2 hours, 1 minute, and 30 seconds
40 test(std::chrono::milliseconds( 7290000), std::chrono::hours( 3));
41 test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2));
42 test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122));
43 test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-121));
46 // 9000000ms is 2 hours and 30 minutes
47 constexpr std::chrono::hours h1
= std::chrono::ceil
<std::chrono::hours
>(std::chrono::milliseconds(9000000));
48 static_assert(h1
.count() == 3, "");
49 constexpr std::chrono::hours h2
= std::chrono::ceil
<std::chrono::hours
>(std::chrono::milliseconds(-9000000));
50 static_assert(h2
.count() == -2, "");