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 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // template <class Duration>
14 // constexpr chrono::hours hours() const noexcept;
17 // duration hours minutes seconds fractional
19 // 5000 minutes 83 20 0 0
20 // 123456789ms 34 17 36 789ms
21 // 123456789us 0 2 3 456789us
22 // 123456789ns 0 0 0 123456789ns
23 // 1000mfn 0 20 9 0.6 (6000/10000)
32 #include "test_macros.h"
34 template <typename Duration
>
35 constexpr long check_hours(Duration d
)
37 using HMS
= std::chrono::hh_mm_ss
<Duration
>;
38 ASSERT_SAME_TYPE(std::chrono::hours
, decltype(std::declval
<HMS
>().hours()));
39 ASSERT_NOEXCEPT( std::declval
<HMS
>().hours());
40 return HMS(d
).hours().count();
45 using microfortnights
= std::chrono::duration
<int, std::ratio
<756, 625>>;
47 static_assert( check_hours(std::chrono::minutes( 1)) == 0, "");
48 static_assert( check_hours(std::chrono::minutes(-1)) == 0, "");
50 assert( check_hours(std::chrono::seconds( 5000)) == 1);
51 assert( check_hours(std::chrono::seconds(-5000)) == 1);
52 assert( check_hours(std::chrono::minutes( 5000)) == 83);
53 assert( check_hours(std::chrono::minutes(-5000)) == 83);
54 assert( check_hours(std::chrono::hours( 11)) == 11);
55 assert( check_hours(std::chrono::hours(-11)) == 11);
57 assert( check_hours(std::chrono::milliseconds( 123456789LL)) == 34);
58 assert( check_hours(std::chrono::milliseconds(-123456789LL)) == 34);
59 assert( check_hours(std::chrono::microseconds( 123456789LL)) == 0);
60 assert( check_hours(std::chrono::microseconds(-123456789LL)) == 0);
61 assert( check_hours(std::chrono::nanoseconds( 123456789LL)) == 0);
62 assert( check_hours(std::chrono::nanoseconds(-123456789LL)) == 0);
64 assert( check_hours(microfortnights( 1000)) == 0);
65 assert( check_hours(microfortnights( -1000)) == 0);
66 assert( check_hours(microfortnights( 10000)) == 3);
67 assert( check_hours(microfortnights(-10000)) == 3);