Skip to content

GH-51215: [C++] Migrate remaining datetime consumers to the chrono shim - #51216

Open
rok wants to merge 4 commits into
apache:mainfrom
rok:gh-51215-chrono-shim
Open

GH-51215: [C++] Migrate remaining datetime consumers to the chrono shim#51216
rok wants to merge 4 commits into
apache:mainfrom
rok:gh-51215-chrono-shim

Conversation

@rok

@rok rok commented Sep 7, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Follow up on #48593 / #48601 - migrate remaining uses of arrow_vendored::date to arrow::internal::chrono, using std::chrono where 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.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #51215 has been automatically assigned in GitHub to PR creator.

@rok
rok force-pushed the gh-51215-chrono-shim branch 2 times, most recently from 3e23a57 to d22fc96 Compare September 7, 2026 15:50
@rok

rok commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit verify-rc-source-windows test-build-vcpkg-win

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Revision: d22fc96

Submitted crossbow builds: ursacomputing/crossbow @ actions-ef7574f790

Task Status
test-build-vcpkg-win GitHub Actions
verify-rc-source-windows GitHub Actions

@rok

rok commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

After #51211 is merged we can completely move to the arrow::internal::chrono shim, which will make it easier to reason about which library is being used for temporal operations and eventually move off of the vendored date.h.

@rok

rok commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit verify-rc-source-windows test-build-vcpkg-win

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Revision: ef7d5fe

Submitted crossbow builds: ursacomputing/crossbow @ actions-41c0a4fab7

Task Status
test-build-vcpkg-win GitHub Actions
verify-rc-source-windows GitHub Actions

@rok
rok force-pushed the gh-51215-chrono-shim branch from ef7d5fe to a5d7ef9 Compare September 7, 2026 18:58
@rok

rok commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit verify-rc-source-windows test-build-vcpkg-win

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Revision: a5d7ef9

Submitted crossbow builds: ursacomputing/crossbow @ actions-1c32742fcc

Task Status
test-build-vcpkg-win GitHub Actions
verify-rc-source-windows GitHub Actions

@rok
rok force-pushed the gh-51215-chrono-shim branch 3 times, most recently from b69f711 to fdcaf7e Compare September 7, 2026 22:48
@rok

rok commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit verify-rc-source-windows test-build-vcpkg-win

@rok

rok commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@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.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Revision: fdcaf7e

Submitted crossbow builds: ursacomputing/crossbow @ actions-6ed6db4ecf

Task Status
test-build-vcpkg-win GitHub Actions
verify-rc-source-windows GitHub Actions

@pitrou

pitrou commented Sep 8, 2026

Copy link
Copy Markdown
Member

@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.

I think it does.

@rok
rok force-pushed the gh-51215-chrono-shim branch 2 times, most recently from ba0f5f3 to 27b9bd4 Compare September 8, 2026 15:48
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.
@rok
rok force-pushed the gh-51215-chrono-shim branch 2 times, most recently from dd9b10c to 09d3c61 Compare September 8, 2026 16:52
@rok

rok commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

@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

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Revision: 09d3c61

Submitted crossbow builds: ursacomputing/crossbow @ actions-51d00219e4

Task Status
r-binary-packages GitHub Actions
test-build-vcpkg-win GitHub Actions
test-r-alpine-linux-cran GitHub Actions
test-r-fedora-clang GitHub Actions
test-r-linux-as-cran GitHub Actions
test-r-macos-as-cran GitHub Actions
verify-rc-source-windows GitHub Actions

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Revision: 6dbcec4

Submitted crossbow builds: ursacomputing/crossbow @ actions-33aa9ce534

Task Status
r-binary-packages GitHub Actions
test-build-vcpkg-win GitHub Actions
test-r-alpine-linux-cran GitHub Actions
test-r-fedora-clang GitHub Actions
test-r-linux-as-cran GitHub Actions
test-r-macos-as-cran GitHub Actions
verify-rc-source-windows GitHub Actions

@rok

rok commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit test-debian-experimental-cpp-gcc-16

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Revision: 2a05f39

Submitted crossbow builds: ursacomputing/crossbow @ actions-6604537ea7

Task Status
test-debian-experimental-cpp-gcc-16 GitHub Actions

@lriggs

lriggs commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

The gandiva changes look good.

@rok

rok commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

The gandiva changes look good.

Thanks for reviewing @lriggs!

@rok

rok commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit test-debian-experimental-cpp-gcc-16

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Revision: fe99b79

Submitted crossbow builds: ursacomputing/crossbow @ actions-b091cd8d4e

Task Status
test-debian-experimental-cpp-gcc-16 GitHub Actions

@rok

rok commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@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

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Revision: fe99b79

Submitted crossbow builds: ursacomputing/crossbow @ actions-9a9adb0e6a

Task Status
r-binary-packages GitHub Actions
test-build-vcpkg-win GitHub Actions
test-r-alpine-linux-cran GitHub Actions
test-r-fedora-clang GitHub Actions
test-r-linux-as-cran GitHub Actions
test-r-macos-as-cran GitHub Actions
verify-rc-source-windows GitHub Actions

@rok
rok marked this pull request as ready for review September 9, 2026 14:20
@rok
rok requested a review from pitrou as a code owner September 9, 2026 14:20
Copilot AI lite review requested due to automatic review settings September 9, 2026 14:20
@rok

rok commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@pitrou this is ready for review. I am pretty confident in parts other than string handling in cpp/src/arrow/util/chrono_internal.h, where I'm not sure we want to keep arrow-specific behaviour or switch over to std::chrono behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.h and refactors chrono_internal.h to centralize backend selection and align timezone implementation compilation with that choice.
  • Updates remaining core and Gandiva datetime users to use arrow::internal::chrono types/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.

@rok
rok requested a balanced review from Copilot September 9, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Comment thread dev/tasks/tasks.yml
Comment on lines +455 to +464
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Unchanged" from what?

Comment on lines +22 to +23
// Share backend selection with the vendored implementation without including its
// headers. datetime.h undefines macros needed when compiling the implementation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "the implementation"? Which one?

Did you generate this using AI?

Comment on lines +29 to +30
// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be moved up?

// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this implicitly call the to_stream above? If not, why doesn't it do the same `ToChronoFormat call?

Comment on lines +25 to +26
# The automatic rule excludes internal headers, but these are dependencies of
# the installed formatting.h and value_parsing.h headers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why make them internal?

Comment on lines +26 to +27
// Emit log via the default logger. Token-paste here to prevent Windows' ERROR
// macro from expanding before the logger macro is selected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line?

Comment on lines +18 to +19
// Evaluate automatic backend selection only when the build has not selected one.
#ifndef ARROW_USE_STD_CHRONO

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the guard? Just include the file and it won't do anything if ARROW_USE_STD_CHRONO is defined, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants