GH-51215: [C++] Migrate remaining datetime consumers to the chrono shim - #51216
GH-51215: [C++] Migrate remaining datetime consumers to the chrono shim#51216rok wants to merge 4 commits into
Conversation
|
|
3e23a57 to
d22fc96
Compare
|
@github-actions crossbow submit verify-rc-source-windows test-build-vcpkg-win |
|
Revision: d22fc96 Submitted crossbow builds: ursacomputing/crossbow @ actions-ef7574f790
|
|
After #51211 is merged we can completely move to the |
|
@github-actions crossbow submit verify-rc-source-windows test-build-vcpkg-win |
|
Revision: ef7d5fe Submitted crossbow builds: ursacomputing/crossbow @ actions-41c0a4fab7
|
ef7d5fe to
a5d7ef9
Compare
|
@github-actions crossbow submit verify-rc-source-windows test-build-vcpkg-win |
|
Revision: a5d7ef9 Submitted crossbow builds: ursacomputing/crossbow @ actions-1c32742fcc
|
b69f711 to
fdcaf7e
Compare
|
@github-actions crossbow submit verify-rc-source-windows test-build-vcpkg-win |
|
@pitrou does approach of this PR make sense? Especialy cpp/src/arrow/util/chrono_config_internal.h. If it does I'll polish it and push it to review. |
|
Revision: fdcaf7e Submitted crossbow builds: ursacomputing/crossbow @ actions-6ed6db4ecf
|
I think it does. |
ba0f5f3 to
27b9bd4
Compare
Route datetime consumers in Arrow and Gandiva through arrow::internal::chrono. Prefer std::chrono when the standard library has reliable C++20 timezone support, while retaining the vendored fallback and allowing an explicit backend override. Compile the vendored timezone sources, including the Apple helper, only when the fallback backend is selected.
dd9b10c to
09d3c61
Compare
|
@github-actions crossbow submit test-r-fedora-clang test-r-linux-as-cran test-r-alpine-linux-cran test-r-macos-as-cran r-binary-packages verify-rc-source-windows test-build-vcpkg-win |
|
Revision: 09d3c61 Submitted crossbow builds: ursacomputing/crossbow @ actions-51d00219e4
|
|
Revision: 6dbcec4 Submitted crossbow builds: ursacomputing/crossbow @ actions-33aa9ce534
|
|
@github-actions crossbow submit test-debian-experimental-cpp-gcc-16 |
|
Revision: 2a05f39 Submitted crossbow builds: ursacomputing/crossbow @ actions-6604537ea7
|
|
The gandiva changes look good. |
Thanks for reviewing @lriggs! |
|
@github-actions crossbow submit test-debian-experimental-cpp-gcc-16 |
|
Revision: fe99b79 Submitted crossbow builds: ursacomputing/crossbow @ actions-b091cd8d4e
|
|
@github-actions crossbow submit test-r-fedora-clang test-r-linux-as-cran test-r-alpine-linux-cran test-r-macos-as-cran r-binary-packages verify-rc-source-windows test-build-vcpkg-win |
|
Revision: fe99b79 Submitted crossbow builds: ursacomputing/crossbow @ actions-9a9adb0e6a
|
|
@pitrou this is ready for review. I am pretty confident in parts other than string handling in |
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core datetime formatting/parsing and timezone-backend selection across Arrow and Gandiva, so it needs careful human validation across supported platforms/stdlib combinations.
Pull request overview
This PR continues Arrow C++’s migration away from arrow_vendored::date call sites by routing remaining parsing/formatting/calendar/timezone consumers (including Gandiva) through the arrow::internal::chrono shim, while preserving backend selection (std::chrono where supported, vendored fallback otherwise) behind a shared configuration header.
Changes:
- Introduces
chrono_config_internal.hand refactorschrono_internal.hto centralize backend selection and align timezone implementation compilation with that choice. - Updates remaining core and Gandiva datetime users to use
arrow::internal::chronotypes/APIs (calendar types, sys/local time, tz helpers). - Adjusts tests and runtime configuration behavior to reflect “OS/stdlib-managed tzdb” vs Arrow-managed tzdb, and adds CI coverage targeting newer libstdc++ behavior.
File summaries
| File | Description |
|---|---|
| dev/tasks/tasks.yml | Adds a Debian experimental GCC 16 CI task to exercise newer libstdc++ chrono/timezone behavior. |
| cpp/src/gandiva/to_date_holder.cc | Removes direct vendored datetime include (callers now rely on chrono shim transitively). |
| cpp/src/gandiva/precompiled/timestamp_arithmetic.cc | Switches year_month_day usage to arrow::internal::chrono types. |
| cpp/src/gandiva/precompiled/time.cc | Switches precompiled date parsing helpers to arrow::internal::chrono calendar types. |
| cpp/src/gandiva/precompiled/epoch_time_point.h | Replaces relative vendored include with arrow/util/chrono_internal.h and updates calendar/time-of-day utilities accordingly. |
| cpp/src/gandiva/gdv_function_stubs.cc | Uses chrono shim timezone APIs (locate_zone, zoned_time, sys_time) for UTC/local conversions. |
| cpp/src/gandiva/cast_time.cc | Switches timezone/date computations from vendored date to chrono shim. |
| cpp/src/arrow/vendored/datetime.cpp | Avoids compiling a second vendored timezone implementation when std-chrono backend is selected. |
| cpp/src/arrow/vendored/datetime_ios.mm | Adds an iOS wrapper to conditionally compile vendored timezone implementation depending on backend selection. |
| cpp/src/arrow/util/value_parsing.h | Migrates date/timestamp parsing helpers from vendored date types to chrono shim types. |
| cpp/src/arrow/util/meson.build | Installs the new internal chrono headers needed by installed public headers. |
| cpp/src/arrow/util/logger_test.cc | Changes test logging macro expansion to avoid Windows ERROR macro collisions. |
| cpp/src/arrow/util/formatting.h | Migrates formatting helpers from vendored date to chrono shim types and adjusts comments accordingly. |
| cpp/src/arrow/util/CMakeLists.txt | Explicitly installs internal chrono headers as dependencies of installed headers. |
| cpp/src/arrow/util/chrono_internal.h | Refactors chrono shim: backend selection moved out, and std-backend formatting now preserves Arrow strftime compatibility (incl. literal braces/unsupported directives). |
| cpp/src/arrow/util/chrono_config_internal.h | New shared compile-time backend selection header (includes libstdc++ version gating for known tz bugs). |
| cpp/src/arrow/testing/util.cc | Skips vendored tzdb initialization when runtime reports OS/stdlib-managed tzdb. |
| cpp/src/arrow/public_api_test.cc | Extends timezone configuration tests for OS/stdlib tzdb builds and validates rejection of runtime tzdb path. |
| cpp/src/arrow/pretty_print.cc | Removes unused vendored datetime include. |
| cpp/src/arrow/config.h | Clarifies RuntimeInfo::using_os_timezone_db semantics to include stdlib-managed tzdb. |
| cpp/src/arrow/config.cc | Routes runtime tzdb behavior through chrono shim configuration macros and functions. |
| cpp/src/arrow/compute/kernels/scalar_temporal_test.cc | Adds strftime syntax compatibility tests (braces, unsupported directives, %Q/%q behavior). |
| cpp/src/arrow/compute/kernels/scalar_cast_temporal.cc | Migrates Date32 duration type from vendored days to chrono shim days. |
| cpp/src/arrow/CMakeLists.txt | Ensures iOS vendored timezone compilation is wrapped to respect std-chrono backend selection. |
| cpp/src/arrow/array/diff.cc | Migrates date/time formatting in array diff output to chrono shim formatting. |
| cpp/src/arrow/acero/test_util_internal.cc | Makes dummy_schema() static (small test utility refactor). |
Review details
- Files reviewed: 26/26 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-platform timezone backend selection and formatting compatibility warrant final human review despite the targeted coverage.
Review details
- Files reviewed: 26/26 changed files
- Comments generated: 0 new
- Review effort level: Balanced
| test-debian-experimental-cpp-gcc-16: | ||
| ci: github | ||
| template: docker-tests/github.linux.yml | ||
| params: | ||
| env: | ||
| ARCH: "amd64" | ||
| DEBIAN: "experimental" | ||
| GCC: "16" | ||
| LLVM: "22" | ||
| image: debian-cpp |
There was a problem hiding this comment.
Note: I'm adding a newer debian image here to get GCC with newer std::chrono so that the std backend gets test tested on linux as well. I'm ok if we exclude this form the final change.
| // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116110 (fully fixed in GCC 16.2). | ||
| // Check library macros, not __GNUC__, so Clang using libstdc++ agrees with GCC. | ||
| // The datestamp distinguishes 16.2 (2026-08-07) from 16.1 and early snapshots. | ||
| // Keep the existing Windows backend selection unchanged. |
| // Share backend selection with the vendored implementation without including its | ||
| // headers. datetime.h undefines macros needed when compiling the implementation. |
There was a problem hiding this comment.
What is "the implementation"? Which one?
Did you generate this using AI?
| // Use the standard backend by default. Builds may explicitly define | ||
| // ARROW_USE_STD_CHRONO to 0 or 1 when they need to select a backend. |
| // Use the standard backend by default. Builds may explicitly define | ||
| // ARROW_USE_STD_CHRONO to 0 or 1 when they need to select a backend. | ||
| // | ||
| // Automatically disable the default for libraries without the C++20 timezone APIs. |
There was a problem hiding this comment.
"Disable the default" is a bit cryptic. Please be explciit.
| // Automatically disable the default for libraries without the C++20 timezone APIs. | ||
| // On non-Windows, older libstdc++ versions also need the fallback because of | ||
| // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116110 (fully fixed in GCC 16.2). | ||
| // Check library macros, not __GNUC__, so Clang using libstdc++ agrees with GCC. |
There was a problem hiding this comment.
This sentence is of little value. Obviously we use libstdc++ symbols when checking for libstdc++...
| // Format a duration or time point using strftime-like format specifiers. | ||
| // Converts "%H%M" style to C++20's "{:L%H%M}" style and uses std::vformat. | ||
| template <typename Temporal> | ||
| std::string format(const char* fmt, const Temporal& value) { |
There was a problem hiding this comment.
Does this implicitly call the to_stream above? If not, why doesn't it do the same `ToChronoFormat call?
| # The automatic rule excludes internal headers, but these are dependencies of | ||
| # the installed formatting.h and value_parsing.h headers. |
| // Emit log via the default logger. Token-paste here to prevent Windows' ERROR | ||
| // macro from expanding before the logger macro is selected. |
There was a problem hiding this comment.
Why did this suddenly start to occur?
| // Standard-library builds must not compile a second timezone implementation. | ||
| #if !ARROW_USE_STD_CHRONO | ||
| # include "datetime/visibility.h" | ||
|
|
| // Evaluate automatic backend selection only when the build has not selected one. | ||
| #ifndef ARROW_USE_STD_CHRONO |
There was a problem hiding this comment.
Why the guard? Just include the file and it won't do anything if ARROW_USE_STD_CHRONO is defined, right?
Rationale for this change
Follow up on #48593 / #48601 - migrate remaining uses of
arrow_vendored::datetoarrow::internal::chrono, usingstd::chronowhere supported.What changes are included in this PR?
Route core calendar, parsing, formatting, and Gandiva callers through arrow::internal::chrono. Preserve backend selection and the vendored fallback, with a shared configuration header guarding the timezone implementation.
Are these changes tested?
By existing tests in CI.
Are there any user-facing changes?
Hopefully no.
AI disclosure: this was in large part generated by AI. However I am familiar with the codebase somewhat and have reviewed proposed changes manually.