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 local_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 ptr tz = cr::locate_zone("Etc/GMT+1");
34 cr::zoned_time<cr::seconds> zt{tz, cr::local_seconds{cr::seconds{0}}};
35
36 assert(zt.get_time_zone() == tz);
37 assert(zt.get_sys_time() == cr::sys_seconds{cr::hours{1}});
38 }
39 {
40 using ptr = offset_time_zone<offset_time_zone_flags::none>;
41 ptr tz{"60"};
42 cr::zoned_time<cr::seconds, ptr> zt{tz, cr::local_seconds{cr::seconds{42}}};
43
44 assert(zt.get_time_zone().offset() == tz.offset());
45 assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{102}});
46 }
47 {
48 using ptr = offset_time_zone<offset_time_zone_flags::has_default_zone>;
49 static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, ptr>);
50 static_assert(!std::convertible_to<ptr, cr::zoned_time<cr::seconds, ptr>>);
51
52 ptr tz{"60"};
53 cr::zoned_time<cr::seconds, ptr> zt{tz, cr::local_seconds{cr::seconds{42}}};
54
55 assert(zt.get_time_zone().offset() == tz.offset());
56 assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{102}});
57 }
58 {
59 using ptr = offset_time_zone<offset_time_zone_flags::has_locate_zone>;
60 static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, ptr>);
61 static_assert(!std::convertible_to<ptr, cr::zoned_time<cr::seconds, ptr>>);
62
63 ptr tz{"60"};
64 cr::zoned_time<cr::seconds, ptr> zt{tz, cr::local_seconds{cr::seconds{42}}};
65
66 assert(zt.get_time_zone().offset() == tz.offset());
67 assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{102}});
68 }
69 {
70 using ptr = offset_time_zone<offset_time_zone_flags::both>;
71 static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, ptr>);
72 static_assert(!std::convertible_to<ptr, cr::zoned_time<cr::seconds, ptr>>);
73
74 ptr tz{"60"};
75 cr::zoned_time<cr::seconds, ptr> zt{tz, cr::local_seconds{cr::seconds{42}}};
76
77 assert(zt.get_time_zone().offset() == tz.offset());
78 assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{102}});
79 }
80
81 return 0;
82}
83

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