| 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, choose c); |
| 21 | |
| 22 | #include <chrono> |
| 23 | #include <cassert> |
| 24 | #include <concepts> |
| 25 | |
| 26 | #include "../test_offset_time_zone.h" |
| 27 | |
| 28 | namespace cr = std::chrono; |
| 29 | |
| 30 | int main(int, char**) { |
| 31 | // Tests unique conversions. To make sure the test does not depend on changes |
| 32 | // in the database it uses a time zone with a fixed offset. |
| 33 | { |
| 34 | cr::zoned_time<cr::seconds> zt{"Etc/GMT+1" , cr::local_seconds{cr::seconds{0}}, cr::choose::earliest}; |
| 35 | |
| 36 | assert(zt.get_time_zone() == cr::locate_zone("Etc/GMT+1" )); |
| 37 | assert(zt.get_sys_time() == cr::sys_seconds{cr::hours{1}}); |
| 38 | } |
| 39 | |
| 40 | // Tests ambiguous conversions. |
| 41 | { |
| 42 | // Z Europe/Berlin 0:53:28 - LMT 1893 Ap |
| 43 | // ... |
| 44 | // 1 DE CE%sT 1980 |
| 45 | // 1 E CE%sT |
| 46 | // |
| 47 | // ... |
| 48 | // R E 1981 ma - Mar lastSu 1u 1 S |
| 49 | // R E 1996 ma - O lastSu 1u 0 - |
| 50 | |
| 51 | using namespace std::literals::chrono_literals; |
| 52 | { |
| 53 | cr::zoned_time<cr::seconds> zt{ |
| 54 | "Europe/Berlin" , |
| 55 | cr::local_seconds{(cr::sys_days{cr::September / 28 / 1986} + 2h + 30min).time_since_epoch()}, |
| 56 | cr::choose::earliest}; |
| 57 | |
| 58 | assert(zt.get_time_zone() == cr::locate_zone("Europe/Berlin" )); |
| 59 | assert(zt.get_sys_time() == cr::sys_days{cr::September / 28 / 1986} + 0h + 30min); |
| 60 | } |
| 61 | { |
| 62 | cr::zoned_time<cr::seconds> zt{ |
| 63 | "Europe/Berlin" , |
| 64 | cr::local_seconds{(cr::sys_days{cr::September / 28 / 1986} + 2h + 30min).time_since_epoch()}, |
| 65 | cr::choose::latest}; |
| 66 | |
| 67 | assert(zt.get_time_zone() == cr::locate_zone("Europe/Berlin" )); |
| 68 | assert(zt.get_sys_time() == cr::sys_days{cr::September / 28 / 1986} + 1h + 30min); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | static_assert(std::constructible_from<cr::zoned_time<cr::seconds, const cr::time_zone*>, |
| 73 | std::string_view, |
| 74 | cr::local_seconds, |
| 75 | cr::choose>); |
| 76 | |
| 77 | static_assert(!std::constructible_from< cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::none>>, |
| 78 | std::string_view, |
| 79 | cr::local_seconds, |
| 80 | cr::choose>); |
| 81 | |
| 82 | static_assert( |
| 83 | !std::constructible_from< cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::has_default_zone>>, |
| 84 | std::string_view, |
| 85 | cr::local_seconds, |
| 86 | cr::choose>); |
| 87 | |
| 88 | static_assert( |
| 89 | !std::constructible_from< cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::has_locate_zone>>, |
| 90 | std::string_view, |
| 91 | cr::local_seconds, |
| 92 | cr::choose>); |
| 93 | |
| 94 | static_assert(!std::constructible_from< cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::both>>, |
| 95 | std::string_view, |
| 96 | cr::local_seconds, |
| 97 | cr::choose>); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |