[libcxx-commits] [libcxx] [libc++][TZDB] Implements zoned_time's operator==. (PR #95140)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 10 05:25:59 PDT 2024


https://github.com/mordante updated https://github.com/llvm/llvm-project/pull/95140

>From c2640df8e10eec183cf4972d1465cad4c5789c34 Mon Sep 17 00:00:00 2001
From: Mark de Wever <koraq at xs4all.nl>
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements zoned_time's operator==.

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
- P1614R2 The Mothership has Landed
---
 libcxx/docs/Status/SpaceshipProjects.csv      |  4 +-
 libcxx/include/__chrono/zoned_time.h          |  6 ++
 libcxx/include/chrono                         |  4 ++
 .../std/numerics/bit/bitops.rot/rotl.pass.cpp |  5 +-
 .../eq.pass.cpp                               | 69 +++++++++++++++++++
 5 files changed, 85 insertions(+), 3 deletions(-)
 create mode 100644 libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp

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 ae84c6c2e6ac5..8fb17b2bc4741 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 cfadeaaa3c1ed..5c4bfbeaa867d 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/numerics/bit/bitops.rot/rotl.pass.cpp b/libcxx/test/std/numerics/bit/bitops.rot/rotl.pass.cpp
index 50e498b5761e5..6bbcb08014c02 100644
--- a/libcxx/test/std/numerics/bit/bitops.rot/rotl.pass.cpp
+++ b/libcxx/test/std/numerics/bit/bitops.rot/rotl.pass.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// ADDITIONAL_COMPILE_FLAGS: -fsanitize=implicit-integer-sign-change
+
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
 // template <class T>
@@ -20,6 +22,7 @@
 #include <type_traits>
 
 #include "test_macros.h"
+#include <cstdint>
 
 struct A {};
 enum       E1 : unsigned char { rEd };
@@ -40,7 +43,7 @@ constexpr bool test()
     assert(std::rotl(T(max - 1), 4) == T(max - 16));
     assert(std::rotl(T(max - 1), 5) == T(max - 32));
     assert(std::rotl(T(max - 1), 6) == T(max - 64));
-    assert(std::rotl(T(max - 1), 7) == T(max - 128));
+(void)    std::rotl(T(max - 1), -2147483648);
 
     assert(std::rotl(T(max - 1), -1) == T(max - highbit));
     assert(std::rotl(T(max - 1), -2) == T(max - (highbit >> 1)));
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..11425a5185d77
--- /dev/null
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
+
+// XFAIL: libcpp-has-no-experimental-tzdb
+// XFAIL: availability-tzdb-missing
+
+// <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;
+}



More information about the libcxx-commits mailing list