| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 |
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb |
| 11 |
|
| 12 |
// XFAIL: libcpp-has-no-experimental-tzdb |
| 13 |
// XFAIL: availability-tzdb-missing |
| 14 |
|
| 15 |
// <chrono> |
| 16 |
|
| 17 |
// zoned_time() -> zoned_time<seconds>; |
| 18 |
// |
| 19 |
// template<class Duration> |
| 20 |
// zoned_time(sys_time<Duration>) |
| 21 |
// -> zoned_time<common_type_t<Duration, seconds>>; |
| 22 |
// |
| 23 |
// template<class TimeZonePtrOrName> |
| 24 |
// using time-zone-representation = // exposition only |
| 25 |
// conditional_t<is_convertible_v<TimeZonePtrOrName, string_view>, |
| 26 |
// const time_zone*, |
| 27 |
// remove_cvref_t<TimeZonePtrOrName>>; |
| 28 |
// |
| 29 |
// template<class TimeZonePtrOrName> |
| 30 |
// zoned_time(TimeZonePtrOrName&&) |
| 31 |
// -> zoned_time<seconds, time-zone-representation<TimeZonePtrOrName>>; |
| 32 |
// |
| 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>>; |
| 37 |
// |
| 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>>; |
| 43 |
// |
| 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>>; |
| 49 |
|
| 50 |
#include <chrono> |
| 51 |
#include <concepts> |
| 52 |
#include <string> |
| 53 |
|
| 54 |
#include "test_offset_time_zone.h" |
| 55 |
|
| 56 |
namespace cr = std::chrono; |
| 57 |
|
| 58 |
// Verify the results of the constructed object. |
| 59 |
int main(int, char**) { |
| 60 |
{ |
| 61 |
// zoned_time() -> zoned_time<seconds>; |
| 62 |
cr::zoned_time zt; |
| 63 |
static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>); |
| 64 |
} |
| 65 |
|
| 66 |
{ |
| 67 |
// template<class Duration> |
| 68 |
// zoned_time(sys_time<Duration>) |
| 69 |
// -> zoned_time<common_type_t<Duration, seconds>>; |
| 70 |
{ |
| 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*>>); |
| 73 |
} |
| 74 |
{ |
| 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*>>); |
| 77 |
} |
| 78 |
{ |
| 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*>>); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
{ |
| 85 |
// template<class TimeZonePtrOrName> |
| 86 |
// zoned_time(TimeZonePtrOrName&&) |
| 87 |
// -> zoned_time<seconds, time-zone-representation<TimeZonePtrOrName>>; |
| 88 |
{ // Name |
| 89 |
{ |
| 90 |
cr::zoned_time zt{"UTC"}; |
| 91 |
static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>); |
| 92 |
} |
| 93 |
{ |
| 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*>>); |
| 96 |
} |
| 97 |
{ |
| 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*>>); |
| 100 |
} |
| 101 |
} |
| 102 |
{ // TimeZonePtr |
| 103 |
{ |
| 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*>>); |
| 106 |
} |
| 107 |
{ |
| 108 |
cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::none>{}}; |
| 109 |
static_assert( |
| 110 |
std::same_as< decltype(zt), cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::none>>>); |
| 111 |
} |
| 112 |
{ |
| 113 |
cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::has_default_zone>{}}; |
| 114 |
static_assert( |
| 115 |
std::same_as<decltype(zt), |
| 116 |
cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::has_default_zone>>>); |
| 117 |
} |
| 118 |
{ |
| 119 |
cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::has_locate_zone>{}}; |
| 120 |
static_assert( |
| 121 |
std::same_as<decltype(zt), |
| 122 |
cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::has_locate_zone>>>); |
| 123 |
} |
| 124 |
{ |
| 125 |
cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::both>{}}; |
| 126 |
static_assert( |
| 127 |
std::same_as< decltype(zt), cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::both>>>); |
| 128 |
} |
| 129 |
|
| 130 |
// There are no requirements on the TimeZonePtr type. |
| 131 |
{ |
| 132 |
cr::zoned_time zt{0}; |
| 133 |
static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, int>>); |
| 134 |
} |
| 135 |
{ |
| 136 |
cr::zoned_time zt{0.0}; |
| 137 |
static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, double>>); |
| 138 |
} |
| 139 |
{ |
| 140 |
cr::zoned_time zt{cr::seconds{}}; |
| 141 |
static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, cr::seconds>>); |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
{ |
| 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>>; |
| 151 |
{ // Name |
| 152 |
{ |
| 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*>>); |
| 155 |
} |
| 156 |
{ |
| 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*>>); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
{ // TimeZonePtr |
| 163 |
{ |
| 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*>>); |
| 166 |
} |
| 167 |
{ |
| 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*>>); |
| 170 |
} |
| 171 |
{ |
| 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>>>); |
| 175 |
} |
| 176 |
{ |
| 177 |
cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::none>{}, cr::sys_time<cr::days>{}}; |
| 178 |
static_assert( |
| 179 |
std::same_as< decltype(zt), cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::none>>>); |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
{ |
| 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>>; |
| 190 |
{ // Name |
| 191 |
{ |
| 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*>>); |
| 194 |
} |
| 195 |
{ |
| 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*>>); |
| 198 |
} |
| 199 |
} |
| 200 |
{ // TimeZonePtr |
| 201 |
{ |
| 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*>>); |
| 204 |
} |
| 205 |
{ |
| 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*>>); |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
{ |
| 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>>; |
| 218 |
{ // Name |
| 219 |
{ |
| 220 |
cr::zoned_time zt{ |
| 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*>>); |
| 223 |
} |
| 224 |
{ |
| 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*>>); |
| 229 |
} |
| 230 |
} |
| 231 |
{ // TimeZonePtr |
| 232 |
{ |
| 233 |
cr::zoned_time zt{ |
| 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*>>); |
| 237 |
} |
| 238 |
{ |
| 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*>>); |
| 243 |
} |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
return 0; |
| 248 |
} |