Skip to content

Commit 6ba3dd2

Browse files
committed
Address review comments.
1 parent ef00b4e commit 6ba3dd2

File tree

3 files changed

+110
-8
lines changed

3 files changed

+110
-8
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
}

libcxx/test/std/time/time.zone/time.zone.leap/assign.copy.pass.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,22 @@ constexpr bool test() {
4040
assert(a.date() != b.date());
4141
assert(a.value() != b.value());
4242

43-
std::same_as<std::chrono::leap_second&> decltype(auto) result(b = a);
44-
assert(std::addressof(result) == std::addressof(b));
43+
{
44+
std::same_as<std::chrono::leap_second&> decltype(auto) result(b = a);
45+
assert(std::addressof(result) == std::addressof(b));
4546

46-
assert(a.date() == b.date());
47-
assert(a.value() == b.value());
47+
assert(a.date() == b.date());
48+
assert(a.value() == b.value());
49+
}
50+
51+
{
52+
// Tests an rvalue uses the copy assignment.
53+
std::same_as<std::chrono::leap_second&> decltype(auto) result(b = std::move(a));
54+
assert(std::addressof(result) == std::addressof(b));
55+
56+
assert(a.date() == b.date());
57+
assert(a.value() == b.value());
58+
}
4859

4960
return true;
5061
}

libcxx/test/std/time/time.zone/time.zone.leap/cons.copy.pass.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,27 @@
3232
constexpr bool test() {
3333
std::chrono::leap_second a =
3434
test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1});
35-
std::chrono::leap_second b = a;
3635

37-
// operator== only compares the date member.
38-
assert(a.date() == b.date());
39-
assert(a.value() == b.value());
36+
{
37+
std::chrono::leap_second b = a;
38+
39+
// operator== only compares the date member.
40+
assert(a.date() == b.date());
41+
assert(a.value() == b.value());
42+
}
43+
44+
#ifdef _LIBCPP_VERSION
45+
{
46+
// Tests an rvalue uses the copy constructor.
47+
// Since implementations are allowed to add additional constructors this is
48+
// a libc++ specific test.
49+
std::chrono::leap_second b = std::move(a);
50+
51+
// operator== only compares the date member.
52+
assert(a.date() == b.date());
53+
assert(a.value() == b.value());
54+
}
55+
#endif // _LIBCPP_VERSION
4056

4157
return true;
4258
}

0 commit comments

Comments
 (0)