Debian Codegraph @

libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/time_zone_pointer.pass.cpp

raw
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 // explicit zoned_time(TimeZonePtr z);
21
22 #include <chrono>
23 #include <concepts>
24
25 #include "../test_offset_time_zone.h"
26
27 // Verify the results of the constructed object.
28 int main(int, char**) {
29 {
30 using ptr = const std::chrono::time_zone*;
31 static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, ptr>);
32 static_assert(!std::convertible_to<ptr, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
33
34 ptr tz = std::chrono::locate_zone("UTC");
35 std::chrono::zoned_time<std::chrono::seconds> zt{tz};
36
37 assert(zt.get_time_zone() == tz);
38 assert(zt.get_sys_time() == std::chrono::sys_seconds{});
39 }
40
41 {
42 using ptr = offset_time_zone<offset_time_zone_flags::none>;
43 static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, ptr>);
44 static_assert(!std::convertible_to<ptr, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
45
46 ptr tz;
47 std::chrono::zoned_time<std::chrono::seconds, ptr> zt{tz};
48
49 assert(zt.get_time_zone().offset() == tz.offset());
50 assert(zt.get_sys_time() == std::chrono::sys_seconds{});
51 }
52 {
53 using ptr = offset_time_zone<offset_time_zone_flags::has_default_zone>;
54 static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, ptr>);
55 static_assert(!std::convertible_to<ptr, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
56
57 ptr tz;
58 std::chrono::zoned_time<std::chrono::seconds, ptr> zt{tz};
59
60 assert(zt.get_time_zone().offset() == tz.offset());
61 assert(zt.get_sys_time() == std::chrono::sys_seconds{});
62 }
63 {
64 using ptr = offset_time_zone<offset_time_zone_flags::has_locate_zone>;
65 static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, ptr>);
66 static_assert(!std::convertible_to<ptr, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
67
68 ptr tz;
69 std::chrono::zoned_time<std::chrono::seconds, ptr> zt{tz};
70
71 assert(zt.get_time_zone().offset() == tz.offset());
72 assert(zt.get_sys_time() == std::chrono::sys_seconds{});
73 }
74 {
75 using ptr = offset_time_zone<offset_time_zone_flags::both>;
76 static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, ptr>);
77 static_assert(!std::convertible_to<ptr, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
78
79 ptr tz;
80 std::chrono::zoned_time<std::chrono::seconds, ptr> zt{tz};
81
82 assert(zt.get_time_zone().offset() == tz.offset());
83 assert(zt.get_sys_time() == std::chrono::sys_seconds{});
84 }
85
86 return 0;
87 }