Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / time / time.zone / time.zone.zonedtime / time.zone.zonedtime.members / get_local_time.pass.cpp
blob017d073789f7dad9a9a29a4f7d425a3d1afe4274
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 //===----------------------------------------------------------------------===//
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
15 // <chrono>
17 // template<class Duration, class TimeZonePtr = const time_zone*>
18 // class zoned_time;
20 // local_time<duration> get_local_time() const;
22 #include <chrono>
23 #include <cassert>
24 #include <concepts>
26 #include "../test_offset_time_zone.h"
28 namespace cr = std::chrono;
30 static void test_callable_with_non_const_and_const_objects() {
32 using duration = cr::nanoseconds;
33 using time_point = cr::sys_time<duration>;
34 using local_time_point = cr::local_time<duration>;
35 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
37 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
38 assert(time == local_time_point{duration{42} - cr::hours{1}});
41 using duration = cr::nanoseconds;
42 using time_point = cr::sys_time<duration>;
43 using local_time_point = cr::local_time<duration>;
44 const cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
46 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
47 assert(time == local_time_point{duration{42} - cr::hours{1}});
51 static void test_duration_conversion() {
52 // common_type_t<duration, seconds> -> duration
54 using duration = cr::nanoseconds;
55 using time_point = cr::sys_time<duration>;
56 using local_time_point = cr::local_time<duration>;
57 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
59 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
60 assert(time == local_time_point{duration{42} - cr::hours{1}});
63 using duration = cr::microseconds;
64 using time_point = cr::sys_time<duration>;
65 using local_time_point = cr::local_time<duration>;
66 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
68 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
69 assert(time == local_time_point{duration{42} - cr::hours{1}});
72 using duration = cr::milliseconds;
73 using time_point = cr::sys_time<duration>;
74 using local_time_point = cr::local_time<duration>;
75 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
77 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
78 assert(time == local_time_point{duration{42} - cr::hours{1}});
80 // common_type_t<seconds, seconds> -> seconds
82 using duration = cr::seconds;
83 using time_point = cr::sys_time<duration>;
84 using local_time_point = cr::local_time<duration>;
85 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
87 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
88 assert(time == local_time_point{duration{42} - cr::hours{1}});
90 // common_type_t<duration, seconds> -> seconds
92 using duration = cr::days;
93 using time_point = cr::sys_time<duration>;
94 using local_time_point = cr::local_time<cr::seconds>;
95 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
97 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
98 assert(time == local_time_point{duration{42} - cr::hours{1}});
101 using duration = cr::weeks;
102 using time_point = cr::sys_time<duration>;
103 using local_time_point = cr::local_time<cr::seconds>;
104 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
106 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
107 assert(time == local_time_point{duration{42} - cr::hours{1}});
110 using duration = cr::months;
111 using time_point = cr::sys_time<duration>;
112 using local_time_point = cr::local_time<cr::seconds>;
113 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
115 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
116 assert(time == local_time_point{duration{42} - cr::hours{1}});
119 using duration = cr::years;
120 using time_point = cr::sys_time<duration>;
121 using local_time_point = cr::local_time<cr::seconds>;
122 cr::zoned_time<duration> zt{"Etc/GMT+1", time_point{duration{42}}};
124 std::same_as<local_time_point> decltype(auto) time = zt.get_local_time();
125 assert(time == local_time_point{duration{42} - cr::hours{1}});
129 int main(int, char**) {
130 test_callable_with_non_const_and_const_objects();
131 test_duration_conversion();
133 return 0;