2121// / \brief Abstraction layer for C++20 chrono calendar/timezone APIs
2222// /
2323// / This header provides a unified interface for chrono calendar and timezone
24- // / functionality. On compilers with full C++20 chrono support, it uses
25- // / std::chrono. On other compilers, it falls back to the vendored Howard Hinnant
26- // / date library .
24+ // / functionality. It uses std::chrono on supported Windows standard libraries
25+ // / and otherwise falls back to the vendored Howard Hinnant date library.
26+ // / See chrono_config_internal.h for backend selection .
2727// /
28- // / The main benefit is on Windows where std::chrono uses the system timezone
29- // / database, eliminating the need for users to install IANA tzdata separately.
28+ // / On Windows with MSVC, std::chrono uses the system timezone database,
29+ // / eliminating the need for users to install IANA tzdata separately.
3030
3131#include < chrono>
3232#include < string>
3333#include < string_view>
3434
35- // Feature detection for C++20 chrono timezone support
36- // https://en.cppreference.com/w/cpp/compiler_support/20.html#cpp_lib_chrono_201907L
37- //
38- // On Windows with MSVC: std::chrono uses Windows' internal timezone database,
39- // eliminating the need for users to install IANA tzdata separately.
40- //
41- // On Windows with MinGW/GCC: libstdc++ reads tzdata files via TZDIR env var.
42- // Set TZDIR=/usr/share/zoneinfo to use the system tzdata.
43- //
44- // On non-Windows: GCC libstdc++ has a bug where DST state is incorrectly reset when
45- // a timezone transitions between rule sets (e.g., Australia/Broken_Hill around
46- // 2000-02-29). Until this is fixed, we use the vendored date.h library.
47- // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116110
48-
49- // Use std::chrono on Windows when C++20 chrono timezone support is available.
50- // The __cpp_lib_chrono >= 201907L feature test macro indicates full support:
51- // - MSVC: Uses Windows' internal timezone database (no IANA tzdata needed)
52- // - GCC/libstdc++: Requires TZDIR environment variable to locate tzdata
53- // - Clang/libc++: Does not define 201907L (no timezone support), so falls back
54- //
55- // On non-Windows, we use the vendored date library due to a GCC libstdc++ bug
56- // where DST state is incorrectly reset during timezone rule transitions.
57- // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116110
58- #if defined(_WIN32) && defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907L
59- # define ARROW_USE_STD_CHRONO 1
60- #else
61- # define ARROW_USE_STD_CHRONO 0
62- #endif
35+ #include " arrow/util/chrono_config_internal.h"
6336
6437#if ARROW_USE_STD_CHRONO
6538// Use C++20 standard library chrono
@@ -162,11 +135,11 @@ std::basic_ostream<CharT, Traits>& to_stream(
162135 return os;
163136}
164137
165- // Format a duration using strftime-like format specifiers
166- // Converts "%H%M" style to C++20's "{:%H%M}" style and uses std::vformat
167- template <typename Duration >
168- std::string format (const char * fmt, const Duration& d ) {
169- return std::vformat (std::string (" {:" ) + fmt + " }" , std::make_format_args (d ));
138+ // Format a duration or time point using strftime-like format specifiers.
139+ // Converts "%H%M" style to C++20's "{:%H%M}" style and uses std::vformat.
140+ template <typename Temporal >
141+ std::string format (const char * fmt, const Temporal& value ) {
142+ return std::vformat (std::string (" {:" ) + fmt + " }" , std::make_format_args (value ));
170143}
171144
172145inline constexpr std::chrono::month jan = std::chrono::January;
@@ -248,6 +221,11 @@ inline const time_zone* locate_zone(std::string_view tz_name) {
248221
249222inline const time_zone* current_zone () { return vendored::current_zone (); }
250223
224+ # if !ARROW_CHRONO_USE_OS_TZDB
225+ using vendored::reload_tzdb;
226+ using vendored::set_install;
227+ # endif
228+
251229// Formatting support
252230using vendored::format;
253231
@@ -270,4 +248,11 @@ inline constexpr vendored::last_spec last = vendored::last;
270248
271249#endif // ARROW_USE_STD_CHRONO
272250
251+ // date::make_time has no std::chrono equivalent, but hh_mm_ss is shared by both
252+ // backends. Keep duration deduction here for callers formatting time of day.
253+ template <typename Rep, typename Period>
254+ constexpr auto make_time (std::chrono::duration<Rep, Period> value) {
255+ return hh_mm_ss<std::chrono::duration<Rep, Period>>{value};
256+ }
257+
273258} // namespace arrow::internal::chrono
0 commit comments