Debian Codegraph @

libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view_local_time.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 // zoned_time(string_view name, const local_time<Duration>& st);
21
22 #include <chrono>
23 #include <concepts>
24
25 #include "../test_offset_time_zone.h"
26
27 namespace cr = std::chrono;
28
29 // Verify the results of the constructed object.
30 int main(int, char**) {
31 {
32 using ptr = const cr::time_zone*;
33 static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::sys_seconds>);
34
35 cr::zoned_time<cr::seconds> zt{"Etc/GMT+1", cr::local_seconds{cr::seconds{0}}};
36
37 assert(zt.get_time_zone() == cr::locate_zone("Etc/GMT+1"));
38 assert(zt.get_sys_time() == cr::sys_seconds{cr::hours{1}});
39 }
40
41 {
42 using ptr = offset_time_zone<offset_time_zone_flags::none>;
43 static_assert(!std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::local_seconds>);
44 }
45
46 {
47 using ptr = offset_time_zone<offset_time_zone_flags::has_default_zone>;
48 static_assert(!std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::local_seconds>);
49 }
50
51 {
52 using ptr = offset_time_zone<offset_time_zone_flags::has_locate_zone>;
53 static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::local_seconds>);
54
55 ptr tz;
56 cr::zoned_time<cr::seconds, ptr> zt{"42", cr::local_seconds{cr::seconds{99}}};
57
58 assert(zt.get_time_zone().offset() == cr::seconds{42});
59 assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{141}});
60 }
61
62 {
63 using ptr = offset_time_zone<offset_time_zone_flags::both>;
64 static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::local_seconds>);
65
66 ptr tz;
67 cr::zoned_time<cr::seconds, ptr> zt{"42", cr::local_seconds{cr::seconds{99}}};
68
69 assert(zt.get_time_zone().offset() == cr::seconds{42});
70 assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{141}});
71 }
72
73 return 0;
74 }