Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f2d8cc

Browse files
authored
[libc++][chrono] Loads leap-seconds.list in tzdb. (llvm#82113)
This implements the loading of the leap-seconds.list file and store its contents in the tzdb struct. This adds the required `leap_seconds` member. The class leap_seconds is fully implemented including its non-member functions. Implements parts of: - P0355 Extending <chrono> to Calendars and Time Zones - P1614 The Mothership has Landed Implements: - P1981 Rename leap to leap_second - LWG3359 <chrono> leap second support should allow for negative leap seconds - LWG3383 §[time.zone.leap.nonmembers] sys_seconds should be replaced with seconds
1 parent 72e2e4f commit 6f2d8cc

25 files changed

+852
-23
lines changed

libcxx/docs/Status/Cxx20Issues.csv

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
"`3355 <https://wg21.link/LWG3355>`__","The memory algorithms should support move-only input iterators introduced by P1207","Prague","|Complete|","15.0","|ranges|"
270270
"`3356 <https://wg21.link/LWG3356>`__","``__cpp_lib_nothrow_convertible``\ should be ``__cpp_lib_is_nothrow_convertible``\ ","Prague","|Complete|","12.0"
271271
"`3358 <https://wg21.link/LWG3358>`__","|sect|\ [span.cons] is mistaken that ``to_address``\ can throw","Prague","|Complete|","17.0"
272-
"`3359 <https://wg21.link/LWG3359>`__","``<chrono>``\ leap second support should allow for negative leap seconds","Prague","","","|chrono|"
272+
"`3359 <https://wg21.link/LWG3359>`__","``<chrono>``\ leap second support should allow for negative leap seconds","Prague","|Complete|","19.0","|chrono|"
273273
"`3360 <https://wg21.link/LWG3360>`__","``three_way_comparable_with``\ is inconsistent with similar concepts","Prague","|Nothing To Do|","","|spaceship|"
274274
"`3362 <https://wg21.link/LWG3362>`__","Strike ``stop_source``\ 's ``operator!=``\ ","Prague","",""
275275
"`3363 <https://wg21.link/LWG3363>`__","``drop_while_view``\ should opt-out of ``sized_range``\ ","Prague","|Nothing To Do|","","|ranges|"
@@ -286,7 +286,7 @@
286286
"`3380 <https://wg21.link/LWG3380>`__","``common_type``\ and comparison categories","Prague","|Complete|","15.0","|spaceship|"
287287
"`3381 <https://wg21.link/LWG3381>`__","``begin``\ and ``data``\ must agree for ``contiguous_range``\ ","Prague","|Nothing To Do|","","|ranges|"
288288
"`3382 <https://wg21.link/LWG3382>`__","NTTP for ``pair``\ and ``array``\ ","Prague","",""
289-
"`3383 <https://wg21.link/LWG3383>`__","|sect|\ [time.zone.leap.nonmembers] ``sys_seconds``\ should be replaced with ``seconds``\ ","Prague","","","|chrono|"
289+
"`3383 <https://wg21.link/LWG3383>`__","|sect|\ [time.zone.leap.nonmembers] ``sys_seconds``\ should be replaced with ``seconds``\ ","Prague","|Complete|","19.0","|chrono|"
290290
"`3384 <https://wg21.link/LWG3384>`__","``transform_view::*sentinel*``\ has an incorrect ``operator-``\ ","Prague","|Complete|","15.0","|ranges|"
291291
"`3385 <https://wg21.link/LWG3385>`__","``common_iterator``\ is not sufficiently constrained for non-copyable iterators","Prague","|Complete|","15.0","|ranges|"
292292
"`3387 <https://wg21.link/LWG3387>`__","|sect|\ [range.reverse.view] ``reverse_view<V>``\ unintentionally requires ``range<const V>``\ ","Prague","|Complete|","15.0","|ranges|"

libcxx/docs/Status/Cxx20Papers.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"`P1970R2 <https://wg21.link/P1970R2>`__","LWG","Consistency for size() functions: Add ranges::ssize","Prague","|Complete|","15.0","|ranges|"
180180
"`P1973R1 <https://wg21.link/P1973R1>`__","LWG","Rename ""_default_init"" Functions, Rev1","Prague","|Complete|","16.0"
181181
"`P1976R2 <https://wg21.link/P1976R2>`__","LWG","Fixed-size span construction from dynamic range","Prague","|Complete|","11.0","|ranges|"
182-
"`P1981R0 <https://wg21.link/P1981R0>`__","LWG","Rename leap to leap_second","Prague","* *",""
182+
"`P1981R0 <https://wg21.link/P1981R0>`__","LWG","Rename leap to leap_second","Prague","|Complete|","19.0","|chrono|"
183183
"`P1982R0 <https://wg21.link/P1982R0>`__","LWG","Rename link to time_zone_link","Prague","|Complete|","19.0","|chrono|"
184184
"`P1983R0 <https://wg21.link/P1983R0>`__","LWG","Wording for GB301, US296, US292, US291, and US283","Prague","|Complete|","15.0","|ranges|"
185185
"`P1994R1 <https://wg21.link/P1994R1>`__","LWG","elements_view needs its own sentinel","Prague","|Complete|","16.0","|ranges|"

libcxx/docs/Status/SpaceshipProjects.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Section,Description,Dependencies,Assignee,Complete
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`",A ``<chrono>`` implementation,Mark de Wever,|Complete|
175175
`[time.zone.zonedtime.nonmembers] <https://wg21.link/time.zone.zonedtime.nonmembers>`_,"`chrono::zoned_time`",A ``<chrono>`` implementation,Mark de Wever,|In Progress|
176-
`[time.zone.leap.nonmembers] <https://wg21.link/time.zone.leap.nonmembers>`_,"`chrono::time_leap_seconds`",A ``<chrono>`` implementation,Mark de Wever,|In Progress|
176+
`[time.zone.leap.nonmembers] <https://wg21.link/time.zone.leap.nonmembers>`_,"`chrono::time_leap_seconds`",A ``<chrono>`` implementation,Mark de Wever,|Complete|
177177
`[time.zone.link.nonmembers] <https://wg21.link/time.zone.link.nonmembers>`_,"`chrono::time_zone_link`",A ``<chrono>`` implementation,Mark de Wever,|Complete|
178178
- `5.13 Clause 28: Localization library <https://wg21.link/p1614r2#clause-28-localization-library>`_,,,,
179179
"| `[locale] <https://wg21.link/locale>`_

libcxx/include/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ set(files
282282
__chrono/formatter.h
283283
__chrono/hh_mm_ss.h
284284
__chrono/high_resolution_clock.h
285+
__chrono/leap_second.h
285286
__chrono/literals.h
286287
__chrono/month.h
287288
__chrono/month_weekday.h

libcxx/include/__chrono/leap_second.h

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
11+
12+
#ifndef _LIBCPP___CHRONO_LEAP_SECOND_H
13+
#define _LIBCPP___CHRONO_LEAP_SECOND_H
14+
15+
#include <version>
16+
// Enable the contents of the header only when libc++ was built with experimental features enabled.
17+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
18+
19+
# include <__chrono/duration.h>
20+
# include <__chrono/system_clock.h>
21+
# include <__chrono/time_point.h>
22+
# include <__compare/ordering.h>
23+
# include <__compare/three_way_comparable.h>
24+
# include <__config>
25+
26+
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27+
# pragma GCC system_header
28+
# endif
29+
30+
_LIBCPP_BEGIN_NAMESPACE_STD
31+
32+
# if _LIBCPP_STD_VER >= 20
33+
34+
namespace chrono {
35+
36+
class leap_second {
37+
public:
38+
struct __constructor_tag;
39+
[[nodiscard]]
40+
_LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__constructor_tag&&, sys_seconds __date, seconds __value)
41+
: __date_(__date), __value_(__value) {}
42+
43+
_LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&) = default;
44+
_LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default;
45+
46+
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; }
47+
48+
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; }
49+
50+
private:
51+
sys_seconds __date_;
52+
seconds __value_;
53+
};
54+
55+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const leap_second& __x, const leap_second& __y) {
56+
return __x.date() == __y.date();
57+
}
58+
59+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) {
60+
return __x.date() <=> __y.date();
61+
}
62+
63+
template <class _Duration>
64+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) {
65+
return __x.date() == __y;
66+
}
67+
68+
template <class _Duration>
69+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) {
70+
return __x.date() < __y;
71+
}
72+
73+
template <class _Duration>
74+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) {
75+
return __x < __y.date();
76+
}
77+
78+
template <class _Duration>
79+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) {
80+
return __y < __x;
81+
}
82+
83+
template <class _Duration>
84+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) {
85+
return __y < __x;
86+
}
87+
88+
template <class _Duration>
89+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) {
90+
return !(__y < __x);
91+
}
92+
93+
template <class _Duration>
94+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) {
95+
return !(__y < __x);
96+
}
97+
98+
template <class _Duration>
99+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) {
100+
return !(__x < __y);
101+
}
102+
103+
template <class _Duration>
104+
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) {
105+
return !(__x < __y);
106+
}
107+
108+
# ifndef _LIBCPP_COMPILER_GCC
109+
// This requirement cause a compilation loop in GCC-13 and running out of memory.
110+
// TODO TZDB Test whether GCC-14 fixes this.
111+
template <class _Duration>
112+
requires three_way_comparable_with<sys_seconds, sys_time<_Duration>>
113+
_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) {
114+
return __x.date() <=> __y;
115+
}
116+
# endif
117+
118+
} // namespace chrono
119+
120+
# endif //_LIBCPP_STD_VER >= 20
121+
122+
_LIBCPP_END_NAMESPACE_STD
123+
124+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
125+
126+
#endif // _LIBCPP___CHRONO_LEAP_SECOND_H

libcxx/include/__chrono/tzdb.h

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// Enable the contents of the header only when libc++ was built with experimental features enabled.
1717
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
1818

19+
# include <__chrono/leap_second.h>
1920
# include <__chrono/time_zone.h>
2021
# include <__chrono/time_zone_link.h>
2122
# include <__config>
@@ -40,6 +41,8 @@ struct tzdb {
4041
string version;
4142
vector<time_zone> zones;
4243
vector<time_zone_link> links;
44+
45+
vector<leap_second> leap_seconds;
4346
};
4447

4548
} // namespace chrono

libcxx/include/chrono

+39
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ struct tzdb {
688688
string version;
689689
vector<time_zone> zones;
690690
vector<time_zone_link> links;
691+
vector<leap_second> leap_seconds;
691692
};
692693
693694
class tzdb_list { // C++20
@@ -731,6 +732,43 @@ class time_zone {
731732
bool operator==(const time_zone& x, const time_zone& y) noexcept; // C++20
732733
strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept; // C++20
733734
735+
// [time.zone.leap], leap second support
736+
class leap_second { // C++20
737+
public:
738+
leap_second(const leap_second&) = default;
739+
leap_second& operator=(const leap_second&) = default;
740+
741+
// unspecified additional constructors
742+
743+
constexpr sys_seconds date() const noexcept;
744+
constexpr seconds value() const noexcept;
745+
};
746+
747+
constexpr bool operator==(const leap_second& x, const leap_second& y); // C++20
748+
constexpr strong_ordering operator<=>(const leap_second& x, const leap_second& y);
749+
750+
template<class Duration> // C++20
751+
constexpr bool operator==(const leap_second& x, const sys_time<Duration>& y);
752+
template<class Duration> // C++20
753+
constexpr bool operator< (const leap_second& x, const sys_time<Duration>& y);
754+
template<class Duration> // C++20
755+
constexpr bool operator< (const sys_time<Duration>& x, const leap_second& y);
756+
template<class Duration> // C++20
757+
constexpr bool operator> (const leap_second& x, const sys_time<Duration>& y);
758+
template<class Duration> // C++20
759+
constexpr bool operator> (const sys_time<Duration>& x, const leap_second& y);
760+
template<class Duration> // C++20
761+
constexpr bool operator<=(const leap_second& x, const sys_time<Duration>& y);
762+
template<class Duration> // C++20
763+
constexpr bool operator<=(const sys_time<Duration>& x, const leap_second& y);
764+
template<class Duration> // C++20
765+
constexpr bool operator>=(const leap_second& x, const sys_time<Duration>& y);
766+
template<class Duration> // C++20
767+
constexpr bool operator>=(const sys_time<Duration>& x, const leap_second& y);
768+
template<class Duration> // C++20
769+
requires three_way_comparable_with<sys_seconds, sys_time<Duration>>
770+
constexpr auto operator<=>(const leap_second& x, const sys_time<Duration>& y);
771+
734772
// [time.zone.link], class time_zone_link
735773
class time_zone_link { // C++20
736774
public:
@@ -862,6 +900,7 @@ constexpr chrono::year operator ""y(unsigned lo
862900

863901
#if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
864902
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
903+
# include <__chrono/leap_second.h>
865904
# include <__chrono/time_zone.h>
866905
# include <__chrono/time_zone_link.h>
867906
# include <__chrono/tzdb.h>

libcxx/include/libcxx.imp

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
{ include: [ "<__chrono/formatter.h>", "private", "<chrono>", "public" ] },
280280
{ include: [ "<__chrono/hh_mm_ss.h>", "private", "<chrono>", "public" ] },
281281
{ include: [ "<__chrono/high_resolution_clock.h>", "private", "<chrono>", "public" ] },
282+
{ include: [ "<__chrono/leap_second.h>", "private", "<chrono>", "public" ] },
282283
{ include: [ "<__chrono/literals.h>", "private", "<chrono>", "public" ] },
283284
{ include: [ "<__chrono/month.h>", "private", "<chrono>", "public" ] },
284285
{ include: [ "<__chrono/month_weekday.h>", "private", "<chrono>", "public" ] },

libcxx/include/module.modulemap

+1
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ module std_private_chrono_high_resolution_clock [system] {
11451145
export std_private_chrono_steady_clock
11461146
export std_private_chrono_system_clock
11471147
}
1148+
module std_private_chrono_leap_second [system] { header "__chrono/leap_second.h" }
11481149
module std_private_chrono_literals [system] { header "__chrono/literals.h" }
11491150
module std_private_chrono_month [system] { header "__chrono/month.h" }
11501151
module std_private_chrono_month_weekday [system] { header "__chrono/month_weekday.h" }

libcxx/modules/std/chrono.inc

+13-15
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ export namespace std {
208208
using std::chrono::reload_tzdb;
209209
using std::chrono::remote_version;
210210

211-
# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
212-
// !defined(_LIBCPP_HAS_NO_LOCALIZATION)
213-
214-
# if 0
211+
# if 0
215212
// [time.zone.exception], exception classes
216213
using std::chrono::ambiguous_local_time;
217214
using std::chrono::nonexistent_local_time;
@@ -221,11 +218,11 @@ export namespace std {
221218

222219
// [time.zone.timezone], class time_zone
223220
using std::chrono::choose;
224-
# endif
225-
# ifdef _LIBCPP_ENABLE_EXPERIMENTAL
221+
# endif // if 0
222+
226223
using std::chrono::time_zone;
227-
# endif
228-
# if 0
224+
225+
# if 0
229226

230227
// [time.zone.zonedtraits], class template zoned_traits
231228
using std::chrono::zoned_traits;
@@ -234,22 +231,23 @@ export namespace std {
234231
using std::chrono::zoned_time;
235232

236233
using std::chrono::zoned_seconds;
234+
# endif // if 0
237235

238236
// [time.zone.leap], leap second support
239237
using std::chrono::leap_second;
240-
# endif
241238

242-
# ifdef _LIBCPP_ENABLE_EXPERIMENTAL
243239
// [time.zone.link], class time_zone_link
244240
using std::chrono::time_zone_link;
245-
# endif
246241

247-
# if 0
242+
# if 0
248243
// [time.format], formatting
249244
using std::chrono::local_time_format;
250-
# endif
251-
#endif // _LIBCPP_ENABLE_EXPERIMENTAL
252-
} // namespace chrono
245+
# endif
246+
# endif // _LIBCPP_ENABLE_EXPERIMENTAL
247+
#endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
248+
// !defined(_LIBCPP_HAS_NO_LOCALIZATION)
249+
250+
} // namespace chrono
253251

254252
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
255253
using std::formatter;

libcxx/src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ endif()
334334

335335
if (LIBCXX_ENABLE_LOCALIZATION AND LIBCXX_ENABLE_FILESYSTEM AND LIBCXX_ENABLE_TIME_ZONE_DATABASE)
336336
list(APPEND LIBCXX_EXPERIMENTAL_SOURCES
337+
include/tzdb/leap_second_private.h
337338
include/tzdb/time_zone_link_private.h
338339
include/tzdb/time_zone_private.h
339340
include/tzdb/types_private.h
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
11+
12+
#ifndef _LIBCPP_SRC_INCLUDE_TZDB_LEAP_SECOND_PRIVATE_H
13+
#define _LIBCPP_SRC_INCLUDE_TZDB_LEAP_SECOND_PRIVATE_H
14+
15+
#include <chrono>
16+
17+
_LIBCPP_BEGIN_NAMESPACE_STD
18+
19+
namespace chrono {
20+
21+
struct leap_second::__constructor_tag {};
22+
23+
} // namespace chrono
24+
25+
_LIBCPP_END_NAMESPACE_STD
26+
27+
#endif // _LIBCPP_SRC_INCLUDE_TZDB_LEAP_SECOND_PRIVATE_H

0 commit comments

Comments
 (0)