Skip to content

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

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

rok wants to merge 12 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.
  • Move backend selection into a shared chrono_config_internal.h, which is also used to guard the vendored timezone sources (datetime.cpp, datetime_ios.mm) so standard-library builds don't compile a second timezone implementation.
  • Enable std::chrono on non-Windows with libstdc++ >= 16.2 (earlier versions are affected by https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116110 and keep using the vendored library).
  • Move strftime-to-std::format translation into TimestampFormatter, preserving Arrow's existing strftime syntax (%Q/%q, %n/%t, unknown directives as literals, braces, etc.).
  • R: set_timezone_database is a no-op when the timezone database isn't configurable (e.g. MinGW builds using std::chrono).
  • CI: add a Debian experimental GCC 16 crossbow job to exercise the std::chrono path on Linux.

Are these changes tested?

Yes. By existing tests, new tests for strftime format translation and formatter stream state, and the new GCC 16 crossbow job.

Are there any user-facing changes?

Yes, for builds that select the std::chrono backend (MSVC, MinGW with C++20 timezone support, and Linux with libstdc++ >= 16.2):

  • arrow::Initialize() with GlobalOptions::timezone_db_path (deprecated since 24.0.0) now returns Invalid, and RuntimeInfo::using_os_timezone_db is true. On MSVC this means the deprecated pyarrow.set_timezone_db_path now raises instead of silently configuring an unused database.
  • libarrow no longer exports the arrow_vendored::date timezone functions (locate_zone, current_zone, reload_tzdb, ...) since the vendored timezone sources are not compiled. Downstream code calling these directly will fail to link against such builds. Calendar types in arrow/vendored/datetime.h are header-only and unaffected.
  • arrow/util/chrono_internal.h and arrow/util/chrono_config_internal.h are now installed, as they are included by the public formatting.h and value_parsing.h headers.

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 4 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

@rok
rok force-pushed the gh-51215-chrono-shim branch from 09d3c61 to 6dbcec4 Compare September 8, 2026 17:23
Copilot AI balanced review requested due to automatic review settings September 30, 2026 07:06
@rok
rok force-pushed the gh-51215-chrono-shim branch from fa624ed to dfb9ed7 Compare September 30, 2026 07:06

This comment was marked as low quality.

- R: skip set_timezone_database when the timezone database is managed by
  the OS or standard library, avoiding a startup error on MinGW builds
- Clarify the Initialize() error message for standard-library backends
- Document backend selection caveats (runtime libstdc++, MinGW, installed
  headers, vendored timezone symbols not exported)
- Avoid a global namespace alias in gandiva's epoch_time_point.h
- Report an error when TimestampFormatter's stream sentry fails
Copilot AI balanced review requested due to automatic review settings September 30, 2026 07:28

This comment was marked as low quality.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 07:34

This comment was marked as low quality.

@rok

rok commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

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

@github-actions

Copy link
Copy Markdown

Revision: 14c50d8

Submitted crossbow builds: ursacomputing/crossbow @ actions-76ecbaf520

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

@raulcd

raulcd commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

The failure on test-debian-experimental-cpp-gcc-16 seems related to the last commit on main coming from:

Testing test-debian-experimental-cpp-gcc-15 as it's probably reproducible there and might be failing on main.

@raulcd

raulcd commented Sep 30, 2026

Copy link
Copy Markdown
Member

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

@github-actions

Copy link
Copy Markdown

Revision: 14c50d8

Submitted crossbow builds: ursacomputing/crossbow @ actions-3fd704e3af

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

Copilot AI balanced review requested due to automatic review settings September 30, 2026 09:22

This comment was marked as low quality.

@rok

rok commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

The failure on test-debian-experimental-cpp-gcc-16 seems related to the last commit on main coming from:

Testing test-debian-experimental-cpp-gcc-15 as it's probably reproducible there and might be failing on main.

The aim with gcc-16 is to test std::chrono on linux (no other compilers we have on linux will currently use that codepath). I can wait for GH-51329 to merge, rebase and check. I don't really want to add test-debian-experimental-cpp-gcc-15 job and this doesn't really block review.

@raulcd

raulcd commented Sep 30, 2026

Copy link
Copy Markdown
Member

Agree, sorry if it was not clear, the failures are completely unrelated to this PR and this PR can be reviewed I was just validating the failure was also happening on gcc15. I've opened an issue to fix those failures (which also happen on main) here:

@rok

rok commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

@pitrou I addressed you comments and this is ready for another round. That said - is this change something we would want to merge before the release or rather afterwards? I'd defer to your judgement.

@pitrou pitrou added the CI: Extra: C++ Run extra C++ CI label Sep 30, 2026
@pitrou

pitrou commented Sep 30, 2026

Copy link
Copy Markdown
Member

@github-actions crossbow submit -g cpp

@github-actions

Copy link
Copy Markdown

Revision: fd2bb12

Submitted crossbow builds: ursacomputing/crossbow @ actions-89610adff7

Task Status
example-cpp-minimal-build-static GitHub Actions
example-cpp-minimal-build-static-system-dependency GitHub Actions
example-cpp-tutorial GitHub Actions
test-build-cpp-fuzz GitHub Actions
test-conda-cpp GitHub Actions
test-conda-cpp-valgrind GitHub Actions
test-debian-13-cpp-amd64 GitHub Actions
test-debian-13-cpp-i386 GitHub Actions
test-debian-experimental-cpp-gcc-15 GitHub Actions
test-debian-experimental-cpp-gcc-16 GitHub Actions
test-fedora-42-cpp GitHub Actions
test-ubuntu-22.04-cpp GitHub Actions
test-ubuntu-22.04-cpp-bundled GitHub Actions
test-ubuntu-22.04-cpp-emscripten GitHub Actions
test-ubuntu-22.04-cpp-no-threading GitHub Actions
test-ubuntu-24.04-cpp GitHub Actions
test-ubuntu-24.04-cpp-gcc-13-bundled GitHub Actions
test-ubuntu-24.04-cpp-gcc-14 GitHub Actions
test-ubuntu-24.04-cpp-minimal-with-formats GitHub Actions
test-ubuntu-24.04-cpp-thread-sanitizer GitHub Actions

}

#if ARROW_USE_STD_CHRONO
TEST(TimestampFormatterTest, CoalesceChronoFields) {

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.

Could you add a comment explaining what this is about?

}
#endif

TEST(TimestampFormatterTest, ReuseFormatter) {

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.

Same, explain why this is useful?

&options_earliest);
}

#if 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.

Some of these tests are not compute-specific, can we move them to a more appropriate place? For example arrow/util/time_test.cc

}
}

TEST(TimestampFormatterTest, NanosecondRangeLimits) {

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.

Do we test for overflow somewhere?

EXPECT_EQ(result, "763145224192 ns");
}

TEST(TimestampFormatterTest, StreamState) {

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 this for exactly? Is it useful? if so, add a comment?

const auto append_literal = [&](char value) {
// Braces and literal percent signs must stay outside chrono replacement fields.
if (value == '{' || value == '}' || value == '%') close_zoned_field();
AppendEscapedLiteral(&out, 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.

If this is the single call site of AppendEscapedLiteral, perhaps it needn't be a separate function at all?

? local_time - local_day
: std::chrono::days{1} - (local_day - local_time);
const auto time_of_day_count = time_of_day.count();
const std::ostream::sentry sentry(bufstream);

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.

Hmm, what is this for/how this snippet work? Can you add explanatory comments?

std::make_format_args(zt, time_of_day, time_of_day_count));
if (end.failed()) bufstream.setstate(std::ios::badbit);
} else {
bufstream.setstate(std::ios::badbit);

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???


template <typename Duration>
struct TimestampFormatter {
static std::string PrepareFormat(const std::string& format) {

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.

Can you make this method protected and move it towards the end of the struct for clarity?

Comment on lines +331 to +332
return detail::ToChronoFormat(
format.c_str(), std::ratio_equal_v<typename Precision::period, std::micro>);

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.

Please add parameter name when it's not obvious.

Suggested change
return detail::ToChronoFormat(
format.c_str(), std::ratio_equal_v<typename Precision::period, std::micro>);
return detail::ToChronoFormat(
format.c_str(), /*xxx=*/ std::ratio_equal_v<typename Precision::period, std::micro>);

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.

5 participants