| 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 |
// 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. |
| 35 |
static const std::array leap_seconds = { |
| 36 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1972y / std::chrono::July / 1}}, 1s), |
| 37 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1973y / std::chrono::January / 1}}, 1s), |
| 38 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1974y / std::chrono::January / 1}}, 1s), |
| 39 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1975y / std::chrono::January / 1}}, 1s), |
| 40 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1976y / std::chrono::January / 1}}, 1s), |
| 41 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1977y / std::chrono::January / 1}}, 1s), |
| 42 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1978y / std::chrono::January / 1}}, 1s), |
| 43 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1979y / std::chrono::January / 1}}, 1s), |
| 44 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1980y / std::chrono::January / 1}}, 1s), |
| 45 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1981y / std::chrono::July / 1}}, 1s), |
| 46 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1982y / std::chrono::July / 1}}, 1s), |
| 47 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1983y / std::chrono::July / 1}}, 1s), |
| 48 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1985y / std::chrono::July / 1}}, 1s), |
| 49 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1988y / std::chrono::January / 1}}, 1s), |
| 50 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1990y / std::chrono::January / 1}}, 1s), |
| 51 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1991y / std::chrono::January / 1}}, 1s), |
| 52 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1992y / std::chrono::July / 1}}, 1s), |
| 53 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1993y / std::chrono::July / 1}}, 1s), |
| 54 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1994y / std::chrono::July / 1}}, 1s), |
| 55 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1996y / std::chrono::January / 1}}, 1s), |
| 56 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1997y / std::chrono::July / 1}}, 1s), |
| 57 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{1999y / std::chrono::January / 1}}, 1s), |
| 58 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2006y / std::chrono::January / 1}}, 1s), |
| 59 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2009y / std::chrono::January / 1}}, 1s), |
| 60 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2012y / std::chrono::July / 1}}, 1s), |
| 61 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2015y / std::chrono::July / 1}}, 1s), |
| 62 |
std::make_pair(std::chrono::sys_seconds{std::chrono::sys_days{2017y / std::chrono::January / 1}}, 1s)}; |
| 63 |
|
| 64 |
int main(int, const char**) { |
| 65 |
const std::chrono::tzdb& tzdb = std::chrono::get_tzdb(); |
| 66 |
|
| 67 |
assert(tzdb.leap_seconds.size() >= leap_seconds.size()); |
| 68 |
assert((std::ranges::equal( |
| 69 |
leap_seconds, |
| 70 |
tzdb.leap_seconds | std::ranges::views::take(leap_seconds.size()), |
| 71 |
[](const auto& lhs, const auto& rhs) { return lhs.first == rhs.date() && lhs.second == rhs.value(); }))); |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |