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