|
| 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-incomplete-tzdb |
| 13 | +// XFAIL: availability-tzdb-missing |
| 14 | + |
| 15 | +// <chrono> |
| 16 | + |
| 17 | +// Tests the loaded leap seconds match |
| 18 | +// https://eel.is/c++draft/time.zone.leap.overview#2 |
| 19 | +// |
| 20 | +// At the moment of writing that list is the actual list. |
| 21 | +// If in the future more leap seconds are added, the returned list may have more |
| 22 | + |
| 23 | +#include <algorithm> |
| 24 | +#include <array> |
| 25 | +#include <cassert> |
| 26 | +#include <chrono> |
| 27 | +#include <ranges> |
| 28 | + |
| 29 | +using namespace std::literals::chrono_literals; |
| 30 | + |
| 31 | +// The list of leap seconds matching |
| 32 | +// https://eel.is/c++draft/time.zone.leap.overview#2 |
| 33 | +// At the moment of writing that list is the actual list in the IANA database. |
| 34 | +// If in the future more leap seconds can be added. Testng th |
| 35 | +static const std::array /*<std::chrono::leap_second>*/ leap_seconds = { |
| 36 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1972y / std::chrono::January / 1}}, 10s), |
| 37 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1972y / std::chrono::July / 1}}, 11s), |
| 38 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1973y / std::chrono::January / 1}}, 12s), |
| 39 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1974y / std::chrono::January / 1}}, 13s), |
| 40 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1975y / std::chrono::January / 1}}, 14s), |
| 41 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1976y / std::chrono::January / 1}}, 15s), |
| 42 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1977y / std::chrono::January / 1}}, 16s), |
| 43 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1978y / std::chrono::January / 1}}, 17s), |
| 44 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1979y / std::chrono::January / 1}}, 18s), |
| 45 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1980y / std::chrono::January / 1}}, 19s), |
| 46 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1981y / std::chrono::July / 1}}, 20s), |
| 47 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1982y / std::chrono::July / 1}}, 21s), |
| 48 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1983y / std::chrono::July / 1}}, 22s), |
| 49 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1985y / std::chrono::July / 1}}, 23s), |
| 50 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1988y / std::chrono::January / 1}}, 24s), |
| 51 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1990y / std::chrono::January / 1}}, 25s), |
| 52 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1991y / std::chrono::January / 1}}, 26s), |
| 53 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1992y / std::chrono::July / 1}}, 27s), |
| 54 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1993y / std::chrono::July / 1}}, 28s), |
| 55 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1994y / std::chrono::July / 1}}, 29s), |
| 56 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1996y / std::chrono::January / 1}}, 30s), |
| 57 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1997y / std::chrono::July / 1}}, 31s), |
| 58 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1999y / std::chrono::January / 1}}, 32s), |
| 59 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2006y / std::chrono::January / 1}}, 33s), |
| 60 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2009y / std::chrono::January / 1}}, 34s), |
| 61 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2012y / std::chrono::July / 1}}, 35s), |
| 62 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2015y / std::chrono::July / 1}}, 36s), |
| 63 | + std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2017y / std::chrono::January / 1}}, 37s)}; |
| 64 | + |
| 65 | +int main(int, const char**) { |
| 66 | + const std::chrono::tzdb& tzdb = std::chrono::get_tzdb(); |
| 67 | + |
| 68 | + assert(tzdb.leap_seconds.size() >= leap_seconds.size()); |
| 69 | + assert((std::ranges::equal( |
| 70 | + leap_seconds, |
| 71 | + tzdb.leap_seconds | std::ranges::views::take(leap_seconds.size()), |
| 72 | + [](const auto& lhs, const auto& rhs) { return lhs.first == rhs.date() && lhs.second == rhs.value(); }))); |
| 73 | + |
| 74 | + return 0; |
| 75 | +} |
0 commit comments