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