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, c++17
10 // UNSUPPORTED: no-filesystem, no-localization, no-tzdb
12 // XFAIL: libcpp-has-no-experimental-tzdb
13 // XFAIL: availability-tzdb-missing
17 // template<class Duration, class TimeZonePtr = const time_zone*>
20 // template<class Duration2>
21 // zoned_time(const zoned_time<Duration2, TimeZonePtr>& y);
27 namespace cr
= std::chrono
;
29 int main(int, char**) {
30 // is_convertible_v<sys_time<Duration2>, sys_time<Duration>> is true.
32 using duration
= cr::microseconds
;
33 using time_point
= cr::sys_time
<duration
>;
34 cr::zoned_time
<duration
> zt
{time_point
{duration
{42}}};
36 using duration2
= cr::nanoseconds
;
37 using time_point2
= cr::sys_time
<duration2
>;
38 static_assert(std::constructible_from
<cr::zoned_time
<duration2
>, cr::zoned_time
<duration
>>);
39 cr::zoned_time
<duration2
> zt2
{zt
};
41 assert(zt2
.get_sys_time() == time_point2
{duration2
{42'000}});
44 using duration
= cr::milliseconds
;
45 using time_point
= cr::sys_time
<duration
>;
46 cr::zoned_time
<duration
> zt
{time_point
{duration
{42}}};
48 using duration2
= cr::nanoseconds
;
49 using time_point2
= cr::sys_time
<duration2
>;
50 static_assert(std::constructible_from
<cr::zoned_time
<duration2
>, cr::zoned_time
<duration
>>);
51 cr::zoned_time
<duration2
> zt2
{zt
};
53 assert(zt2
.get_sys_time() == time_point2
{duration2
{42'000'000}});
56 using duration
= cr::seconds
;
57 using time_point
= cr::sys_time
<duration
>;
58 cr::zoned_time
<duration
> zt
{time_point
{duration
{42}}};
60 using duration2
= cr::nanoseconds
;
61 using time_point2
= cr::sys_time
<duration2
>;
62 static_assert(std::constructible_from
<cr::zoned_time
<duration2
>, cr::zoned_time
<duration
>>);
63 cr::zoned_time
<duration2
> zt2
{zt
};
65 assert(zt2
.get_sys_time() == time_point2
{duration2
{42'000'000'000}});
67 // is_convertible_v<sys_time<Duration2>, sys_time<Duration>> is false.
69 using duration
= cr::milliseconds
;
71 using duration2
= cr::seconds
;
72 static_assert(!std::constructible_from
<cr::zoned_time
<duration2
>, cr::zoned_time
<duration
>>);
75 using duration
= cr::microseconds
;
77 using duration2
= cr::seconds
;
78 static_assert(!std::constructible_from
<cr::zoned_time
<duration2
>, cr::zoned_time
<duration
>>);
81 using duration
= cr::nanoseconds
;
83 using duration2
= cr::seconds
;
84 static_assert(!std::constructible_from
<cr::zoned_time
<duration2
>, cr::zoned_time
<duration
>>);