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 // zoned_time() -> zoned_time<seconds>;
19 // template<class Duration>
20 // zoned_time(sys_time<Duration>)
21 // -> zoned_time<common_type_t<Duration, seconds>>;
23 // template<class TimeZonePtrOrName>
24 // using time-zone-representation = // exposition only
25 // conditional_t<is_convertible_v<TimeZonePtrOrName, string_view>,
27 // remove_cvref_t<TimeZonePtrOrName>>;
29 // template<class TimeZonePtrOrName>
30 // zoned_time(TimeZonePtrOrName&&)
31 // -> zoned_time<seconds, time-zone-representation<TimeZonePtrOrName>>;
33 // template<class TimeZonePtrOrName, class Duration>
34 // zoned_time(TimeZonePtrOrName&&, sys_time<Duration>)
35 // -> zoned_time<common_type_t<Duration, seconds>,
36 // time-zone-representation<TimeZonePtrOrName>>;
38 // template<class TimeZonePtrOrName, class Duration>
39 // zoned_time(TimeZonePtrOrName&&, local_time<Duration>,
40 // choose = choose::earliest)
41 // -> zoned_time<common_type_t<Duration, seconds>,
42 // time-zone-representation<TimeZonePtrOrName>>;
44 // template<class Duration, class TimeZonePtrOrName, class TimeZonePtr2>
45 // zoned_time(TimeZonePtrOrName&&, zoned_time<Duration, TimeZonePtr2>,
46 // choose = choose::earliest)
47 // -> zoned_time<common_type_t<Duration, seconds>,
48 // time-zone-representation<TimeZonePtrOrName>>;
54 #include "test_offset_time_zone.h"
56 namespace cr
= std::chrono
;
58 // Verify the results of the constructed object.
59 int main(int, char**) {
61 // zoned_time() -> zoned_time<seconds>;
63 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
67 // template<class Duration>
68 // zoned_time(sys_time<Duration>)
69 // -> zoned_time<common_type_t<Duration, seconds>>;
71 cr::zoned_time zt
{cr::sys_time
<cr::nanoseconds
>{cr::nanoseconds
{0}}};
72 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::nanoseconds
, const cr::time_zone
*>>);
75 cr::zoned_time zt
{cr::sys_time
<cr::seconds
>{cr::seconds
{0}}};
76 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
79 cr::zoned_time zt
{cr::sys_time
<cr::days
>{cr::days
{0}}};
80 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
85 // template<class TimeZonePtrOrName>
86 // zoned_time(TimeZonePtrOrName&&)
87 // -> zoned_time<seconds, time-zone-representation<TimeZonePtrOrName>>;
90 cr::zoned_time zt
{"UTC"};
91 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
94 cr::zoned_time zt
{std::string
{"UTC"}};
95 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
98 cr::zoned_time zt
{std::string_view
{"UTC"}};
99 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
104 cr::zoned_time zt
{static_cast<const cr::time_zone
*>(nullptr)};
105 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
108 cr::zoned_time zt
{offset_time_zone
<offset_time_zone_flags::none
>{}};
110 std::same_as
< decltype(zt
), cr::zoned_time
<cr::seconds
, offset_time_zone
<offset_time_zone_flags::none
>>>);
113 cr::zoned_time zt
{offset_time_zone
<offset_time_zone_flags::has_default_zone
>{}};
115 std::same_as
<decltype(zt
),
116 cr::zoned_time
<cr::seconds
, offset_time_zone
<offset_time_zone_flags::has_default_zone
>>>);
119 cr::zoned_time zt
{offset_time_zone
<offset_time_zone_flags::has_locate_zone
>{}};
121 std::same_as
<decltype(zt
),
122 cr::zoned_time
<cr::seconds
, offset_time_zone
<offset_time_zone_flags::has_locate_zone
>>>);
125 cr::zoned_time zt
{offset_time_zone
<offset_time_zone_flags::both
>{}};
127 std::same_as
< decltype(zt
), cr::zoned_time
<cr::seconds
, offset_time_zone
<offset_time_zone_flags::both
>>>);
130 // There are no requirements on the TimeZonePtr type.
132 cr::zoned_time zt
{0};
133 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, int>>);
136 cr::zoned_time zt
{0.0};
137 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, double>>);
140 cr::zoned_time zt
{cr::seconds
{}};
141 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, cr::seconds
>>);
147 // template<class TimeZonePtrOrName, class Duration>
148 // zoned_time(TimeZonePtrOrName&&, sys_time<Duration>)
149 // -> zoned_time<common_type_t<Duration, seconds>,
150 // time-zone-representation<TimeZonePtrOrName>>;
153 cr::zoned_time zt
{"UTC", cr::sys_time
<cr::nanoseconds
>{}};
154 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::nanoseconds
, const cr::time_zone
*>>);
157 cr::zoned_time zt
{"UTC", cr::sys_time
<cr::days
>{}};
158 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
164 cr::zoned_time zt
{static_cast<const cr::time_zone
*>(nullptr), cr::sys_time
<cr::nanoseconds
>{}};
165 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::nanoseconds
, const cr::time_zone
*>>);
168 cr::zoned_time zt
{static_cast<const cr::time_zone
*>(nullptr), cr::sys_time
<cr::days
>{}};
169 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
172 cr::zoned_time zt
{offset_time_zone
<offset_time_zone_flags::none
>{}, cr::sys_time
<cr::nanoseconds
>{}};
173 static_assert(std::same_as
< decltype(zt
),
174 cr::zoned_time
<cr::nanoseconds
, offset_time_zone
<offset_time_zone_flags::none
>>>);
177 cr::zoned_time zt
{offset_time_zone
<offset_time_zone_flags::none
>{}, cr::sys_time
<cr::days
>{}};
179 std::same_as
< decltype(zt
), cr::zoned_time
<cr::seconds
, offset_time_zone
<offset_time_zone_flags::none
>>>);
185 // template<class TimeZonePtrOrName, class Duration>
186 // zoned_time(TimeZonePtrOrName&&, local_time<Duration>,
187 // choose = choose::earliest)
188 // -> zoned_time<common_type_t<Duration, seconds>,
189 // time-zone-representation<TimeZonePtrOrName>>;
192 cr::zoned_time zt
{"UTC", cr::local_time
<cr::nanoseconds
>{}};
193 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::nanoseconds
, const cr::time_zone
*>>);
196 cr::zoned_time zt
{"UTC", cr::local_time
<cr::days
>{}, cr::choose::earliest
};
197 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
202 cr::zoned_time zt
{cr::locate_zone("UTC"), cr::local_time
<cr::nanoseconds
>{}};
203 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::nanoseconds
, const cr::time_zone
*>>);
206 cr::zoned_time zt
{cr::locate_zone("UTC"), cr::local_time
<cr::days
>{}, cr::choose::earliest
};
207 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
213 // template<class Duration, class TimeZonePtrOrName, class TimeZonePtr2>
214 // zoned_time(TimeZonePtrOrName&&, zoned_time<Duration, TimeZonePtr2>,
215 // choose = choose::earliest)
216 // -> zoned_time<common_type_t<Duration, seconds>,
217 // time-zone-representation<TimeZonePtrOrName>>;
221 "UTC", cr::zoned_time
<cr::nanoseconds
, offset_time_zone
<offset_time_zone_flags::has_default_zone
>>{}};
222 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::nanoseconds
, const cr::time_zone
*>>);
225 cr::zoned_time zt
{"UTC",
226 cr::zoned_time
<cr::days
, offset_time_zone
<offset_time_zone_flags::has_default_zone
>>{},
227 cr::choose::earliest
};
228 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);
234 cr::locate_zone("UTC"),
235 cr::zoned_time
<cr::nanoseconds
, offset_time_zone
<offset_time_zone_flags::has_default_zone
>>{}};
236 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::nanoseconds
, const cr::time_zone
*>>);
239 cr::zoned_time zt
{cr::locate_zone("UTC"),
240 cr::zoned_time
<cr::days
, offset_time_zone
<offset_time_zone_flags::has_default_zone
>>{},
241 cr::choose::earliest
};
242 static_assert(std::same_as
<decltype(zt
), cr::zoned_time
<cr::seconds
, const cr::time_zone
*>>);