| 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 |
// template<class Duration, class TimeZonePtr = const time_zone*> |
| 18 |
// class zoned_time; |
| 19 |
// |
| 20 |
// zoned_time& operator=(const sys_time<Duration>& st); |
| 21 |
|
| 22 |
#include <cassert> |
| 23 |
#include <chrono> |
| 24 |
#include <concepts> |
| 25 |
#include <type_traits> |
| 26 |
|
| 27 |
namespace cr = std::chrono; |
| 28 |
|
| 29 |
int main(int, char**) { |
| 30 |
{ |
| 31 |
using duration = cr::nanoseconds; |
| 32 |
using time_point = cr::sys_time<duration>; |
| 33 |
using zoned_time = cr::zoned_time<duration>; |
| 34 |
zoned_time zt{time_point{duration{42}}}; |
| 35 |
|
| 36 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 37 |
assert(zt.get_sys_time() == time_point{duration{42}}); |
| 38 |
|
| 39 |
std::same_as<zoned_time&> decltype(auto) result = zt = time_point{duration{99}}; |
| 40 |
assert(&result == &zt); |
| 41 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 42 |
assert(zt.get_sys_time() == time_point{duration{99}}); |
| 43 |
} |
| 44 |
{ |
| 45 |
using duration = cr::microseconds; |
| 46 |
using time_point = cr::sys_time<duration>; |
| 47 |
using zoned_time = cr::zoned_time<duration>; |
| 48 |
zoned_time zt{time_point{duration{42}}}; |
| 49 |
|
| 50 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 51 |
assert(zt.get_sys_time() == time_point{duration{42}}); |
| 52 |
|
| 53 |
std::same_as<zoned_time&> decltype(auto) result = zt = time_point{duration{99}}; |
| 54 |
assert(&result == &zt); |
| 55 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 56 |
assert(zt.get_sys_time() == time_point{duration{99}}); |
| 57 |
} |
| 58 |
{ |
| 59 |
using duration = cr::milliseconds; |
| 60 |
using time_point = cr::sys_time<duration>; |
| 61 |
using zoned_time = cr::zoned_time<duration>; |
| 62 |
zoned_time zt{time_point{duration{42}}}; |
| 63 |
|
| 64 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 65 |
assert(zt.get_sys_time() == time_point{duration{42}}); |
| 66 |
|
| 67 |
std::same_as<zoned_time&> decltype(auto) result = zt = time_point{duration{99}}; |
| 68 |
assert(&result == &zt); |
| 69 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 70 |
assert(zt.get_sys_time() == time_point{duration{99}}); |
| 71 |
} |
| 72 |
{ |
| 73 |
using duration = cr::seconds; |
| 74 |
using time_point = cr::sys_time<duration>; |
| 75 |
using zoned_time = cr::zoned_time<duration>; |
| 76 |
zoned_time zt{time_point{duration{42}}}; |
| 77 |
|
| 78 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 79 |
assert(zt.get_sys_time() == time_point{duration{42}}); |
| 80 |
|
| 81 |
std::same_as<zoned_time&> decltype(auto) result = zt = time_point{duration{99}}; |
| 82 |
assert(&result == &zt); |
| 83 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 84 |
assert(zt.get_sys_time() == time_point{duration{99}}); |
| 85 |
} |
| 86 |
{ |
| 87 |
using duration = cr::days; |
| 88 |
using time_point = cr::sys_time<duration>; |
| 89 |
using zoned_time = cr::zoned_time<duration>; |
| 90 |
zoned_time zt{time_point{duration{42}}}; |
| 91 |
|
| 92 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 93 |
assert(zt.get_sys_time() == time_point{duration{42}}); |
| 94 |
|
| 95 |
std::same_as<zoned_time&> decltype(auto) result = zt = time_point{duration{99}}; |
| 96 |
assert(&result == &zt); |
| 97 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 98 |
assert(zt.get_sys_time() == time_point{duration{99}}); |
| 99 |
} |
| 100 |
{ |
| 101 |
using duration = cr::weeks; |
| 102 |
using time_point = cr::sys_time<duration>; |
| 103 |
using zoned_time = cr::zoned_time<duration>; |
| 104 |
zoned_time zt{time_point{duration{42}}}; |
| 105 |
|
| 106 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 107 |
assert(zt.get_sys_time() == time_point{duration{42}}); |
| 108 |
|
| 109 |
std::same_as<zoned_time&> decltype(auto) result = zt = time_point{duration{99}}; |
| 110 |
assert(&result == &zt); |
| 111 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 112 |
assert(zt.get_sys_time() == time_point{duration{99}}); |
| 113 |
} |
| 114 |
{ |
| 115 |
using duration = cr::months; |
| 116 |
using time_point = cr::sys_time<duration>; |
| 117 |
using zoned_time = cr::zoned_time<duration>; |
| 118 |
zoned_time zt{time_point{duration{42}}}; |
| 119 |
|
| 120 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 121 |
assert(zt.get_sys_time() == time_point{duration{42}}); |
| 122 |
|
| 123 |
std::same_as<zoned_time&> decltype(auto) result = zt = time_point{duration{99}}; |
| 124 |
assert(&result == &zt); |
| 125 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 126 |
assert(zt.get_sys_time() == time_point{duration{99}}); |
| 127 |
} |
| 128 |
{ |
| 129 |
using duration = cr::years; |
| 130 |
using time_point = cr::sys_time<duration>; |
| 131 |
using zoned_time = cr::zoned_time<duration>; |
| 132 |
zoned_time zt{time_point{duration{42}}}; |
| 133 |
|
| 134 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 135 |
assert(zt.get_sys_time() == time_point{duration{42}}); |
| 136 |
|
| 137 |
std::same_as<zoned_time&> decltype(auto) result = zt = time_point{duration{99}}; |
| 138 |
assert(&result == &zt); |
| 139 |
assert(zt.get_time_zone() == cr::locate_zone("UTC")); |
| 140 |
assert(zt.get_sys_time() == time_point{duration{99}}); |
| 141 |
} |
| 142 |
|
| 143 |
return 0; |
| 144 |
} |