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

source code of libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/time_zone_pointer_sys_time.pass.cpp