Skip to content

GH-54641: [C++] Support locale directives in the vendored strptime on Windows - #54656

Merged
kou merged 3 commits into
apache:mainfrom
pearu:pearu/strptime-windows-langinfo
Oct 20, 2026
Merged

kou merged 3 commits into
apache:mainfrom
pearu:pearu/strptime-windows-langinfo

Conversation

@pearu

@pearu pearu commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

On Windows, the vendored musl strptime does not handle %a, %A, %b, %B, %h, %c, %p, %r, %x and %X, because they need nl_langinfo(), which is not available there.

What changes are included in this PR?

A C-locale replacement for nl_langinfo(), restricted to the items the vendored strptime uses, with the values of the POSIX locale.

Are these changes tested?

Yes, TimestampParser.StrptimeLocaleDirectives covers each of these directives. On Windows it exercises the vendored strptime; elsewhere it runs against the system strptime.

Are there any user-facing changes?

On Windows, strptime formats with these directives now parse.

AI usage disclosure

Developed with AI assistance (Claude Code): the fix, the test and this description were AI-generated under my direction and reviewed line by line by me. I own and can debug these changes. No copyrighted material is included.

…ime on Windows

The vendored musl strptime, used on Windows, handles %a, %A, %b, %B, %h,
%c, %p, %r, %x and %X only when nl_langinfo() is available, which it is
not on Windows. Provide a C-locale replacement for the items used.
ARROW_TEST_FALLBACK_LANGINFO compiles the replacement on other platforms.

Drafted by Claude Code (an AI agent) and reviewed & approved by pearu.
@github-actions

Copy link
Copy Markdown

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

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kou kou left a comment

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.

I'm not sure whether we want to maintain a forked strptime() implementation or not but this change is small enough.

Comment thread cpp/src/arrow/vendored/musl/strptime.c Outdated
#undef HAVE_LANGINFO

#ifndef _WIN32
#if !defined(_WIN32) && !defined(ARROW_TEST_FALLBACK_LANGINFO)

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 do we need this change? It seems that ARROW_TEST_FALLBACK_LANGINFO isn't defined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was only for compiling the fallback on Linux for manual testing. Removed; the fallback is tested by StrptimeLocaleDirectives on the Windows CI jobs.

Comment on lines +30 to +40
enum { ABDAY_1 = 0, DAY_1 = 7, ABMON_1 = 14, MON_1 = 26, AM_STR = 38, PM_STR = 39,
D_T_FMT = 40, D_FMT = 41, T_FMT = 42, T_FMT_AMPM = 43 };
static const char *arrow_c_langinfo[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December",
"AM", "PM",
"%a %b %e %T %Y", "%m/%d/%y", "%H:%M:%S", "%I:%M:%S %p"};

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 mention where the values come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They are the values of the POSIX locale (LC_TIME in POSIX.1, chapter 7), which musl's own C locale (c_time in src/locale/langinfo.c) uses in the same order; glibc's C locale has the same values. Added this to the comment.

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Oct 20, 2026
…alues

Drafted by Claude Code (an AI agent) and reviewed & approved by pearu.
@pearu

pearu commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

strptime is already vendored from musl and used on Windows; this PR only provides the nl_langinfo() data it needs there, so the directives that depend on it work.

@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Oct 20, 2026
@pearu
pearu requested a review from kou October 20, 2026 07:34

@kou kou left a comment

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.

+1

Could you try this before we merge this?

diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R
index db036bcdea..2f99b6d750 100644
--- a/r/tests/testthat/test-dplyr-funcs-datetime.R
+++ b/r/tests/testthat/test-dplyr-funcs-datetime.R
@@ -238,8 +238,6 @@ test_that("strptime works for individual formats", {
       collect()
   )
 
-  # Some formats are not supported on Windows
-  skip_on_os("windows")
   expect_equal(
     strptime_test_df |>
       arrow_table() |>

@github-actions github-actions Bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Oct 20, 2026
Drafted by Claude Code (an AI agent) and reviewed & approved by pearu.
@kou

kou commented Oct 20, 2026

Copy link
Copy Markdown
Member

Passed: https://github.com/apache/arrow/actions/runs/39413302527/job/118599671926?pr=54656#step:13:6966

  'test-dplyr-funcs-datetime.R:241:3' [success]

I'll merge this.

@kou
kou merged commit a907fbc into apache:main Oct 20, 2026
61 checks passed
@kou kou removed the awaiting merge Awaiting merge label Oct 20, 2026
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.

3 participants