aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark de Wever <koraq@xs4all.nl>2024-04-17 21:00:22 +0200
committerMark de Wever <koraq@xs4all.nl>2024-07-08 07:42:53 +0200
commit24e1151d23ba3b6b72461498ababb8b0821422ae (patch)
tree483c8fe575075e8ba6e4a0891f0de862148e9363
parent072f4561a2ee3a48dc0754f50ecdec4dbba59421 (diff)
downloadllvm-users/mordante/zoned_time__operator==.zip
llvm-users/mordante/zoned_time__operator==.tar.gz
llvm-users/mordante/zoned_time__operator==.tar.bz2
[libc++][TZDB] Implements zoned_time's operator==.users/mordante/zoned_time__operator==
Implements parts of: - P0355 Extending to chrono Calendars and Time Zones - P1614R2 The Mothership has Landed
-rw-r--r--libcxx/docs/Status/SpaceshipProjects.csv4
-rw-r--r--libcxx/include/__chrono/zoned_time.h6
-rw-r--r--libcxx/include/chrono4
-rw-r--r--libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp71
4 files changed, 83 insertions, 2 deletions
diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv
index 128b23b..74441dc 100644
--- a/libcxx/docs/Status/SpaceshipProjects.csv
+++ b/libcxx/docs/Status/SpaceshipProjects.csv
@@ -140,7 +140,7 @@ Section,Description,Dependencies,Assignee,Complete
"| `[class.slice.overview] <https://wg21.link/class.slice.overview>`_
| `[slice.ops] <https://wg21.link/slice.ops>`_",| `slice <https://reviews.llvm.org/D152617>`_,None,Hristo Hristov,|Complete|
- `5.12 Clause 27: Time library <https://wg21.link/p1614r2#clause-27-time-library>`_,,,,
-| `[time.syn] <https://wg21.link/time.syn>`_,|,None,Mark de Wever,|In Progress|
+| `[time.syn] <https://wg21.link/time.syn>`_,|,None,Mark de Wever,|Complete|
| `[time.duration.comparisons] <https://wg21.link/time.duration.comparisons>`_, `chrono::duration <https://reviews.llvm.org/D145881>`_, None, Hristo Hristov, |Complete|
| `[time.point.comparisons] <https://wg21.link/time.point.comparisons>`_, `chrono::time_point <https://reviews.llvm.org/D146250>`_, None, Hristo Hristov, |Complete|
"| `[time.cal.day.nonmembers] <https://wg21.link/time.cal.day.nonmembers>`_
@@ -172,7 +172,7 @@ Section,Description,Dependencies,Assignee,Complete
| `year_month_weekday <https://reviews.llvm.org/D152699>`_
| `year_month_weekday_last <https://reviews.llvm.org/D152699>`_",None,Hristo Hristov,|Complete|
`[time.zone.nonmembers] <https://wg21.link/time.zone.nonmembers>`_,"`chrono::time_zone`",,Mark de Wever,|Complete|
-`[time.zone.zonedtime.nonmembers] <https://wg21.link/time.zone.zonedtime.nonmembers>`_,"`chrono::zoned_time`",A ``<chrono>`` implementation,Mark de Wever,|In Progress|
+`[time.zone.zonedtime.nonmembers] <https://wg21.link/time.zone.zonedtime.nonmembers>`_,"`chrono::zoned_time`",,Mark de Wever,|Complete|
`[time.zone.leap.nonmembers] <https://wg21.link/time.zone.leap.nonmembers>`_,"`chrono::time_leap_seconds`",,Mark de Wever,|Complete|
`[time.zone.link.nonmembers] <https://wg21.link/time.zone.link.nonmembers>`_,"`chrono::time_zone_link`",,Mark de Wever,|Complete|
- `5.13 Clause 28: Localization library <https://wg21.link/p1614r2#clause-28-localization-library>`_,,,,
diff --git a/libcxx/include/__chrono/zoned_time.h b/libcxx/include/__chrono/zoned_time.h
index 7a13c4e..9be206d 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -205,6 +205,12 @@ template <class _Duration, class _TimeZonePtrOrName, class TimeZonePtr2>
zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = choose::earliest)
-> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
+template <class _Duration1, class _Duration2, class _TimeZonePtr>
+_LIBCPP_HIDE_FROM_ABI bool
+operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const zoned_time<_Duration2, _TimeZonePtr>& __rhs) {
+ return __lhs.get_time_zone() == __rhs.get_time_zone() && __lhs.get_sys_time() == __rhs.get_sys_time();
+}
+
} // namespace chrono
# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index f377a57a..68a7fe3 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -793,6 +793,10 @@ template<class T> struct zoned_traits;
template<class Duration, class TimeZonePtr = const time_zone*> // C++20
class zoned_time;
+template<class Duration1, class Duration2, class TimeZonePtr> // C++20
+ bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
+ const zoned_time<Duration2, TimeZonePtr>& y);
+
// [time.zone.leap], leap second support
class leap_second { // C++20
public:
diff --git a/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
new file mode 100644
index 0000000..2ccb060
--- /dev/null
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// REQUIRES: has-unix-headers
+// REQUIRES: libcpp-hardening-mode={{extensive|debug}}
+// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
+
+// XFAIL: libcpp-has-no-experimental-tzdb
+
+// <chrono>
+
+// template<class Duration1, class Duration2, class TimeZonePtr>
+// bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
+// const zoned_time<Duration2, TimeZonePtr>& y);
+//
+// Note operator!= is generated by the compiler
+
+#include <chrono>
+
+#include "test_comparisons.h"
+
+int main(int, char**) {
+ {
+ std::chrono::zoned_time zt;
+ assert(testEquality(zt, zt, true));
+ }
+ {
+ std::chrono::zoned_time lhs{"UTC"};
+ std::chrono::zoned_time rhs{"Europe/Berlin"};
+ assert(testEquality(lhs, rhs, false));
+ }
+ {
+ std::chrono::zoned_time lhs{"UTC", std::chrono::sys_time<std::chrono::seconds>{std::chrono::seconds{123}}};
+
+ assert(testEquality(lhs,
+ std::chrono::zoned_time{
+ std::chrono::sys_time<std::chrono::nanoseconds>{std::chrono::nanoseconds{123'000'000'000}}},
+ true));
+ assert(testEquality(lhs,
+ std::chrono::zoned_time{
+ std::chrono::sys_time<std::chrono::nanoseconds>{std::chrono::nanoseconds{123'000'000'001}}},
+ false));
+
+ assert(testEquality(lhs,
+ std::chrono::zoned_time{
+ std::chrono::sys_time<std::chrono::microseconds>{std::chrono::microseconds{123'000'000}}},
+ true));
+ assert(testEquality(lhs,
+ std::chrono::zoned_time{
+ std::chrono::sys_time<std::chrono::microseconds>{std::chrono::microseconds{123'000'001}}},
+ false));
+
+ assert(testEquality(
+ lhs,
+ std::chrono::zoned_time{std::chrono::sys_time<std::chrono::milliseconds>{std::chrono::milliseconds{123'000}}},
+ true));
+ assert(testEquality(
+ lhs,
+ std::chrono::zoned_time{std::chrono::sys_time<std::chrono::milliseconds>{std::chrono::milliseconds{123'001}}},
+ false));
+ }
+
+ return 0;
+}