[libcxx-commits] [libcxx] [libc++][TZDB] Adds basics of zoned_time class. (PR #94999)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 10 08:15:54 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Mark de Wever (mordante)
<details>
<summary>Changes</summary>
This implements the class, its non-templated constructors and its getters to verify the construction.
Completes
- LWG3224 zoned_time constructor from TimeZonePtr does not specify initialization of tp_
Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
Patch is 38.46 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/94999.diff
16 Files Affected:
- (modified) libcxx/docs/Status/Cxx20Issues.csv (+1-1)
- (modified) libcxx/include/__chrono/zoned_time.h (+43)
- (modified) libcxx/include/chrono (+4)
- (modified) libcxx/modules/std/chrono.inc (+1-1)
- (modified) libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp (+6)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.assign.pass.cpp (+36)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.ctor.pass.cpp (+43)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/default.pass.cpp (+66)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view.pass.cpp (+77)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/sys_time.pass.cpp (+138)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/time_zone_pointer.pass.cpp (+87)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.members/get_sys_time.pass.cpp (+121)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.members/get_time_zone.pass.cpp (+45)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp (+59)
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/types.verify.cpp (+29)
- (added) libcxx/test/support/test_offset_time_zone.h (+68)
``````````diff
diff --git a/libcxx/docs/Status/Cxx20Issues.csv b/libcxx/docs/Status/Cxx20Issues.csv
index e748ff6ad749b..d4db7876cb2ef 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -165,7 +165,7 @@
"`3225 <https://wg21.link/LWG3225>`__","``zoned_time``\ converting constructor shall not be ``noexcept``\ ","Belfast","","","|chrono|"
"`3190 <https://wg21.link/LWG3190>`__","``std::allocator::allocate``\ sometimes returns too little storage","Belfast","|Complete|","14.0"
"`3218 <https://wg21.link/LWG3218>`__","Modifier for ``%d``\ parse flag does not match POSIX and ``format``\ specification","Belfast","","","|chrono| |format|"
-"`3224 <https://wg21.link/LWG3224>`__","``zoned_time``\ constructor from ``TimeZonePtr``\ does not specify initialization of ``tp_``\ ","Belfast","","","|chrono|"
+"`3224 <https://wg21.link/LWG3224>`__","``zoned_time``\ constructor from ``TimeZonePtr``\ does not specify initialization of ``tp_``\ ","Belfast","|Complete|","19.0","|chrono|"
"`3230 <https://wg21.link/LWG3230>`__","Format specifier ``%y/%Y``\ is missing locale alternative versions","Belfast","|Complete|","16.0","|chrono| |format|"
"`3232 <https://wg21.link/LWG3232>`__","Inconsistency in ``zoned_time``\ deduction guides","Belfast","","","|chrono|"
"`3222 <https://wg21.link/LWG3222>`__","P0574R1 introduced preconditions on non-existent parameters","Belfast","",""
diff --git a/libcxx/include/__chrono/zoned_time.h b/libcxx/include/__chrono/zoned_time.h
index c6084426ad72b..4d9eaabe5d0ed 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -16,10 +16,13 @@
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+# include <__chrono/duration.h>
+# include <__chrono/system_clock.h>
# include <__chrono/time_zone.h>
# include <__chrono/tzdb_list.h>
# include <__config>
# include <__fwd/string_view.h>
+# include <__type_traits/common_type.h>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -43,6 +46,46 @@ struct zoned_traits<const time_zone*> {
}
};
+template <class _Duration, class _TimeZonePtr = const time_zone*>
+class zoned_time {
+ // [time.zone.zonedtime.ctor]/2
+ static_assert(__is_duration<_Duration>::value,
+ "the program is ill-formed since _Duration is not a specialization of std::chrono::duration");
+
+ using __traits = zoned_traits<_TimeZonePtr>;
+
+public:
+ using duration = common_type_t<_Duration, seconds>;
+
+ _LIBCPP_HIDE_FROM_ABI zoned_time()
+ requires requires { __traits::default_zone(); }
+ : __zone_{__traits::default_zone()}, __tp_{} {}
+
+ _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time&) = default;
+ _LIBCPP_HIDE_FROM_ABI zoned_time& operator=(const zoned_time&) = default;
+
+ _LIBCPP_HIDE_FROM_ABI zoned_time(const sys_time<_Duration>& __tp)
+ requires requires { __traits::default_zone(); }
+ : __zone_{__traits::default_zone()}, __tp_{__tp} {}
+
+ _LIBCPP_HIDE_FROM_ABI explicit zoned_time(_TimeZonePtr __zone) : __zone_{std::move(__zone)}, __tp_{} {}
+
+ _LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name)
+ requires(requires { __traits::locate_zone(string_view{}); } &&
+ // constructible_from<zoned_time, decltype(__traits::locate_zone(string_view{}))>
+ // would create a dependency on itself. Instead depend on the fact
+ // a constructor taking a _TimeZonePtr exists.
+ constructible_from<_TimeZonePtr, decltype(__traits::locate_zone(string_view{}))>)
+ : __zone_{__traits::locate_zone(__name)}, __tp_{} {}
+
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _TimeZonePtr get_time_zone() const { return __zone_; }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time<duration> get_sys_time() const { return __tp_; }
+
+private:
+ _TimeZonePtr __zone_;
+ sys_time<duration> __tp_;
+};
+
} // 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 c1a92595ff1f5..026e920342e1e 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -789,6 +789,10 @@ strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept;
// [time.zone.zonedtraits], class template zoned_traits
template<class T> struct zoned_traits; // C++20
+// [time.zone.zonedtime], class template zoned_time
+template<class Duration, class TimeZonePtr = const time_zone*> // C++20
+class zoned_time;
+
// [time.zone.leap], leap second support
class leap_second { // C++20
public:
diff --git a/libcxx/modules/std/chrono.inc b/libcxx/modules/std/chrono.inc
index 87e32afbe4bdc..89fe7284eb694 100644
--- a/libcxx/modules/std/chrono.inc
+++ b/libcxx/modules/std/chrono.inc
@@ -230,10 +230,10 @@ export namespace std {
// [time.zone.zonedtraits], class template zoned_traits
using std::chrono::zoned_traits;
-# if 0
// [time.zone.zonedtime], class template zoned_time
using std::chrono::zoned_time;
+# if 0
using std::chrono::zoned_seconds;
# endif // if 0
diff --git a/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
index 6fed41bdb43ed..e8337cb33822e 100644
--- a/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
@@ -78,4 +78,10 @@ void test() {
t::default_zone(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
t::locate_zone(""); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
+
+ {
+ std::chrono::zoned_time<std::chrono::seconds> zt;
+ zt.get_time_zone(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ zt.get_sys_time(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ }
}
diff --git a/libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.assign.pass.cpp b/libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.assign.pass.cpp
new file mode 100644
index 0000000000000..b74ae06057b8d
--- /dev/null
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.assign.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Duration, class TimeZonePtr = const time_zone*>
+// class zoned_time;
+//
+// zoned_time& operator=(const zoned_time&) = default;
+
+#include <cassert>
+#include <chrono>
+
+int main(int, char**) {
+ std::chrono::zoned_time<std::chrono::seconds> zt{std::chrono::sys_seconds{std::chrono::seconds{42}}};
+ assert(zt.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}});
+
+ std::chrono::zoned_time<std::chrono::seconds> copy;
+ copy = zt;
+ assert(copy.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(copy.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}});
+
+ return 0;
+}
diff --git a/libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.ctor.pass.cpp b/libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.ctor.pass.cpp
new file mode 100644
index 0000000000000..c7a36df2b4b20
--- /dev/null
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.ctor.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Duration, class TimeZonePtr = const time_zone*>
+// class zoned_time;
+//
+// zoned_time(const zoned_time&) = default;
+
+#include <cassert>
+#include <chrono>
+
+int main(int, char**) {
+ std::chrono::zoned_time<std::chrono::seconds> zt{std::chrono::sys_seconds{std::chrono::seconds{42}}};
+ assert(zt.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}});
+
+ {
+ std::chrono::zoned_time<std::chrono::seconds> copy{zt};
+ assert(copy.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(copy.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}});
+ }
+
+ {
+ std::chrono::zoned_time<std::chrono::seconds> copy = zt;
+ assert(copy.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(copy.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}});
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/default.pass.cpp b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/default.pass.cpp
new file mode 100644
index 0000000000000..dd498a9325b31
--- /dev/null
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/default.pass.cpp
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Duration, class TimeZonePtr = const time_zone*>
+// class zoned_time;
+//
+// zoned_time();
+
+#include <chrono>
+#include <concepts>
+#include <type_traits>
+
+#include "test_offset_time_zone.h"
+
+// Verify the results of the default constructed object,
+// and whether the constructor's constrains are satisfied.
+int main(int, char**) {
+ {
+ static_assert(std::default_initializable<std::chrono::zoned_time<std::chrono::seconds>>);
+ std::chrono::zoned_time<std::chrono::seconds> zt;
+ assert(zt.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{});
+ }
+
+ static_assert(!std::default_initializable<
+ std::chrono::zoned_time<std::chrono::seconds, offset_time_zone<offset_time_zone_flags::none>>>);
+
+ {
+ using type = offset_time_zone<offset_time_zone_flags::has_default_zone>;
+ static_assert(std::default_initializable<std::chrono::zoned_time<std::chrono::seconds, type>>);
+
+ std::chrono::zoned_time<std::chrono::seconds, type> zt;
+
+ assert(zt.get_time_zone().offset() == std::chrono::seconds{0});
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{});
+ }
+
+ static_assert(
+ !std::default_initializable<
+ std::chrono::zoned_time<std::chrono::seconds, offset_time_zone<offset_time_zone_flags::has_locate_zone>>>);
+
+ {
+ using type = offset_time_zone<offset_time_zone_flags::both>;
+ static_assert(std::default_initializable<std::chrono::zoned_time<std::chrono::seconds, type>>);
+
+ std::chrono::zoned_time<std::chrono::seconds, type> zt;
+
+ assert(zt.get_time_zone().offset() == std::chrono::seconds{0});
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{});
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view.pass.cpp b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view.pass.cpp
new file mode 100644
index 0000000000000..8b237442a5c97
--- /dev/null
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view.pass.cpp
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Duration, class TimeZonePtr = const time_zone*>
+// class zoned_time;
+//
+// explicit zoned_time(string_view name);
+
+#include <chrono>
+#include <concepts>
+
+#include "test_offset_time_zone.h"
+
+// Verify the results of the constructed object.
+int main(int, char**) {
+ {
+ using ptr = const std::chrono::time_zone*;
+ static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>);
+ static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
+
+ std::chrono::zoned_time<std::chrono::seconds> zt{"UTC"};
+
+ assert(zt.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{});
+ }
+
+ {
+ using ptr = offset_time_zone<offset_time_zone_flags::none>;
+ static_assert(!std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>);
+ static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
+ }
+
+ {
+ using ptr = offset_time_zone<offset_time_zone_flags::has_default_zone>;
+ static_assert(!std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>);
+ static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
+ }
+
+ {
+ using ptr = offset_time_zone<offset_time_zone_flags::has_locate_zone>;
+ static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>);
+ static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
+
+ ptr tz;
+ std::chrono::zoned_time<std::chrono::seconds, ptr> zt{"42"};
+
+ assert(zt.get_time_zone().offset() == std::chrono::seconds{42});
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{});
+ }
+
+ {
+ using ptr = offset_time_zone<offset_time_zone_flags::both>;
+ static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>);
+ static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>);
+
+ ptr tz;
+ std::chrono::zoned_time<std::chrono::seconds, ptr> zt{"42"};
+
+ assert(zt.get_time_zone().offset() == std::chrono::seconds{42});
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{});
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/sys_time.pass.cpp b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/sys_time.pass.cpp
new file mode 100644
index 0000000000000..542024dfa78a5
--- /dev/null
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/sys_time.pass.cpp
@@ -0,0 +1,138 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 Duration, class TimeZonePtr = const time_zone*>
+// class zoned_time;
+//
+// zoned_time(const sys_time<Duration>& st);
+
+#include <chrono>
+#include <concepts>
+#include <type_traits>
+
+#include "test_offset_time_zone.h"
+
+static void test_construction() {
+ static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds>, std::chrono::sys_seconds>);
+ std::chrono::zoned_time<std::chrono::seconds> zt{std::chrono::sys_seconds{std::chrono::seconds{42}}};
+ assert(zt.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}});
+}
+
+static void test_conversion() {
+ static_assert(std::convertible_to<std::chrono::sys_seconds, std::chrono::zoned_time<std::chrono::seconds>>);
+ std::chrono::zoned_time<std::chrono::seconds> zt = std::chrono::sys_seconds{std::chrono::seconds{42}};
+ assert(zt.get_time_zone() == std::chrono::locate_zone("UTC"));
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}});
+}
+
+static void test_duration_conversion() {
+ {
+ using duration = std::chrono::nanoseconds;
+ using time_point = std::chrono::sys_time<duration>;
+ std::chrono::zoned_time<duration> zt{time_point{duration{42}}};
+ assert(zt.get_sys_time() == time_point{duration{42}});
+ }
+ {
+ using duration = std::chrono::microseconds;
+ using time_point = std::chrono::sys_time<duration>;
+ std::chrono::zoned_time<duration> zt{time_point{duration{42}}};
+ assert(zt.get_sys_time() == time_point{duration{42}});
+ }
+ {
+ using duration = std::chrono::milliseconds;
+ using time_point = std::chrono::sys_time<duration>;
+ std::chrono::zoned_time<duration> zt{time_point{duration{42}}};
+ assert(zt.get_sys_time() == time_point{duration{42}});
+ }
+ {
+ using duration = std::chrono::seconds;
+ using time_point = std::chrono::sys_time<duration>;
+ std::chrono::zoned_time<duration> zt{time_point{duration{42}}};
+ assert(zt.get_sys_time() == time_point{duration{42}});
+ }
+ {
+ using duration = std::chrono::days;
+ using time_point = std::chrono::sys_time<duration>;
+ std::chrono::zoned_time<duration> zt{time_point{duration{42}}};
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::days{42}});
+ }
+ {
+ using duration = std::chrono::weeks;
+ using time_point = std::chrono::sys_time<duration>;
+ std::chrono::zoned_time<duration> zt{time_point{duration{42}}};
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::weeks{42}});
+ }
+ {
+ using duration = std::chrono::months;
+ using time_point = std::chrono::sys_time<duration>;
+ std::chrono::zoned_time<duration> zt{time_point{duration{42}}};
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::months{42}});
+ }
+ {
+ using duration = std::chrono::years;
+ using time_point = std::chrono::sys_time<duration>;
+ std::chrono::zoned_time<duration> zt{time_point{duration{42}}};
+ assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::years{42}});
+ }
+}
+
+static void test_duration_constraints() {
+ static_assert(!std::constructible_from<
+ std::chrono::zoned_time<std::chrono::seconds, offset_time_zone<offset_time_zone_flags::none>>,
+ std::chrono::sys_seconds>);
+
+ {
+ using type = offset_time_zone<offset_time_zone_flags::has_default_zone>;
+ static_assert(
+ std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, type>, std::chrono::sys_seconds>);
+
+ std::chrono::zoned_...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/94999
More information about the libcxx-commits
mailing list