-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++][TZDB] Implements zoned_time's operator==. #95140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libcxx Author: Mark de Wever (mordante) ChangesImplements parts of:
Full diff: https://github.com/llvm/llvm-project/pull/95140.diff 4 Files Affected:
diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv
index 128b23b0c2c74..74441dcdea496 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 33e0ac0603a6e..db5e67135d844 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -204,6 +204,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 026e920342e1e..df7ebf45bd907 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 0000000000000..2ccb060d24ee6
--- /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;
+}
|
2d25530
to
072f456
Compare
86dc932
to
24e1151
Compare
ldionne
approved these changes
Jul 9, 2024
libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
Outdated
Show resolved
Hide resolved
072f456
to
4f18b43
Compare
Base automatically changed from
users/mordante/zoned_time__deduction_guides
to
main
July 10, 2024 11:46
32b3172
to
c2640df
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
Implements parts of: - P0355 Extending to chrono Calendars and Time Zones - P1614R2 The Mothership has Landed
c2640df
to
7ec00b6
Compare
aaryanshukla
pushed a commit
to aaryanshukla/llvm-project
that referenced
this pull request
Jul 14, 2024
Implements parts of: - P0355 Extending to chrono Calendars and Time Zones - P1614R2 The Mothership has Landed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements parts of: