Skip to content

Commit 32b3172

Browse files
committed
[libc++][TZDB] Implements zoned_time's operator==.
Implements parts of: - P0355 Extending to chrono Calendars and Time Zones - P1614R2 The Mothership has Landed
1 parent e77b295 commit 32b3172

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

libcxx/docs/Status/SpaceshipProjects.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Section,Description,Dependencies,Assignee,Complete
140140
"| `[class.slice.overview] <https://wg21.link/class.slice.overview>`_
141141
| `[slice.ops] <https://wg21.link/slice.ops>`_",| `slice <https://reviews.llvm.org/D152617>`_,None,Hristo Hristov,|Complete|
142142
- `5.12 Clause 27: Time library <https://wg21.link/p1614r2#clause-27-time-library>`_,,,,
143-
| `[time.syn] <https://wg21.link/time.syn>`_,|,None,Mark de Wever,|In Progress|
143+
| `[time.syn] <https://wg21.link/time.syn>`_,|,None,Mark de Wever,|Complete|
144144
| `[time.duration.comparisons] <https://wg21.link/time.duration.comparisons>`_, `chrono::duration <https://reviews.llvm.org/D145881>`_, None, Hristo Hristov, |Complete|
145145
| `[time.point.comparisons] <https://wg21.link/time.point.comparisons>`_, `chrono::time_point <https://reviews.llvm.org/D146250>`_, None, Hristo Hristov, |Complete|
146146
"| `[time.cal.day.nonmembers] <https://wg21.link/time.cal.day.nonmembers>`_
@@ -172,7 +172,7 @@ Section,Description,Dependencies,Assignee,Complete
172172
| `year_month_weekday <https://reviews.llvm.org/D152699>`_
173173
| `year_month_weekday_last <https://reviews.llvm.org/D152699>`_",None,Hristo Hristov,|Complete|
174174
`[time.zone.nonmembers] <https://wg21.link/time.zone.nonmembers>`_,"`chrono::time_zone`",,Mark de Wever,|Complete|
175-
`[time.zone.zonedtime.nonmembers] <https://wg21.link/time.zone.zonedtime.nonmembers>`_,"`chrono::zoned_time`",A ``<chrono>`` implementation,Mark de Wever,|In Progress|
175+
`[time.zone.zonedtime.nonmembers] <https://wg21.link/time.zone.zonedtime.nonmembers>`_,"`chrono::zoned_time`",,Mark de Wever,|Complete|
176176
`[time.zone.leap.nonmembers] <https://wg21.link/time.zone.leap.nonmembers>`_,"`chrono::time_leap_seconds`",,Mark de Wever,|Complete|
177177
`[time.zone.link.nonmembers] <https://wg21.link/time.zone.link.nonmembers>`_,"`chrono::time_zone_link`",,Mark de Wever,|Complete|
178178
- `5.13 Clause 28: Localization library <https://wg21.link/p1614r2#clause-28-localization-library>`_,,,,

libcxx/include/__chrono/zoned_time.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ template <class _Duration, class _TimeZonePtrOrName, class TimeZonePtr2>
205205
zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = choose::earliest)
206206
-> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
207207

208+
template <class _Duration1, class _Duration2, class _TimeZonePtr>
209+
_LIBCPP_HIDE_FROM_ABI bool
210+
operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const zoned_time<_Duration2, _TimeZonePtr>& __rhs) {
211+
return __lhs.get_time_zone() == __rhs.get_time_zone() && __lhs.get_sys_time() == __rhs.get_sys_time();
212+
}
213+
208214
} // namespace chrono
209215

210216
# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)

libcxx/include/chrono

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,10 @@ template<class T> struct zoned_traits;
793793
template<class Duration, class TimeZonePtr = const time_zone*> // C++20
794794
class zoned_time;
795795
796+
template<class Duration1, class Duration2, class TimeZonePtr> // C++20
797+
bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
798+
const zoned_time<Duration2, TimeZonePtr>& y);
799+
796800
// [time.zone.leap], leap second support
797801
class leap_second { // C++20
798802
public:
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
11+
// XFAIL: libcpp-has-no-experimental-tzdb
12+
13+
// <chrono>
14+
15+
// template<class Duration1, class Duration2, class TimeZonePtr>
16+
// bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
17+
// const zoned_time<Duration2, TimeZonePtr>& y);
18+
//
19+
// Note operator!= is generated by the compiler
20+
21+
#include <chrono>
22+
23+
#include "test_comparisons.h"
24+
25+
int main(int, char**) {
26+
{
27+
std::chrono::zoned_time zt;
28+
assert(testEquality(zt, zt, true));
29+
}
30+
{
31+
std::chrono::zoned_time lhs{"UTC"};
32+
std::chrono::zoned_time rhs{"Europe/Berlin"};
33+
assert(testEquality(lhs, rhs, false));
34+
}
35+
{
36+
std::chrono::zoned_time lhs{"UTC", std::chrono::sys_time<std::chrono::seconds>{std::chrono::seconds{123}}};
37+
38+
assert(testEquality(lhs,
39+
std::chrono::zoned_time{
40+
std::chrono::sys_time<std::chrono::nanoseconds>{std::chrono::nanoseconds{123'000'000'000}}},
41+
true));
42+
assert(testEquality(lhs,
43+
std::chrono::zoned_time{
44+
std::chrono::sys_time<std::chrono::nanoseconds>{std::chrono::nanoseconds{123'000'000'001}}},
45+
false));
46+
47+
assert(testEquality(lhs,
48+
std::chrono::zoned_time{
49+
std::chrono::sys_time<std::chrono::microseconds>{std::chrono::microseconds{123'000'000}}},
50+
true));
51+
assert(testEquality(lhs,
52+
std::chrono::zoned_time{
53+
std::chrono::sys_time<std::chrono::microseconds>{std::chrono::microseconds{123'000'001}}},
54+
false));
55+
56+
assert(testEquality(
57+
lhs,
58+
std::chrono::zoned_time{std::chrono::sys_time<std::chrono::milliseconds>{std::chrono::milliseconds{123'000}}},
59+
true));
60+
assert(testEquality(
61+
lhs,
62+
std::chrono::zoned_time{std::chrono::sys_time<std::chrono::milliseconds>{std::chrono::milliseconds{123'001}}},
63+
false));
64+
}
65+
66+
return 0;
67+
}

0 commit comments

Comments
 (0)