Skip to content

GH-48593: [C++] C++20: use standard calendar / timezone APIs#48601

Open
rok wants to merge 74 commits intoapache:mainfrom
rok:cpp20_use_chrono
Open

GH-48593: [C++] C++20: use standard calendar / timezone APIs#48601
rok wants to merge 74 commits intoapache:mainfrom
rok:cpp20_use_chrono

Conversation

@rok
Copy link
Member

@rok rok commented Dec 19, 2025

Rationale for this change

Switch to std::chrono for MSVC to be able to use the system-provided timezone automatically on Windows.

What changes are included in this PR?

This adds chrono_internal.h that uses C++20 std::chrono timezone/calendar APIs on compilers with support (MSVC only for now) and falls back to vendored date.h otherwise.

Are these changes tested?

Partially tested locally and partially to be tested on CI.

Are there any user-facing changes?

Yes, Windows users will no longer need to install the IANA tzdb (see instructions here and here). We possibly have tzdb download set up in CI too and should update it appropriately.

@github-actions
Copy link

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

@rok rok force-pushed the cpp20_use_chrono branch 9 times, most recently from 4283740 to d82f990 Compare December 23, 2025 18:14
@rok
Copy link
Member Author

rok commented Dec 23, 2025

It seems that std::chrono on GCC (14.3.0, 15.2.0) potentially has a bug that triggers some of our tests. Meanwhile std::chrono on MSVC 19.44 ( 14.44) appears to be pass them and is correct or at least consistent with vendored date.h. I would therefore advise we only switch to std::chrono on MSVC for now as that gives us the most benefit anyway (users no longer have to deal with the tz db).

Below is the explanation and reproduction of the bug.

// GCC libstdc++ DST bug reproduction
//
// The AN to AS Transition Bug
// ---------------------------
// Source https://github.com/eggert/tz/blob/c37fbc3249c1a1334948b38f3bca47dee5c11dd1/australasia#L165-L192
// Australia/Broken_Hill used the AN (New South Wales) rules until 2000, then
// switched to AS (South Australia) rules. Under AN rules, DST started the last
// Sunday of October and ended the last Sunday of March. For the 1999-2000
// summer, DST started October 31, 1999 and would end March 26, 2000. February
// 29, 2000 falls squarely within this DST period, so the correct offset should
// be 9:30 base + 1:00 DST = 10:30 (630 minutes).
//
// Why GCC's Data is Wrong
// -----------------------
// When libstdc++ processes the zone transition from AN rules to AS rules (which
// happens in year 2000), it appears to lose or reset the DST state inherited
// from the AN rules. Instead of recognizing that DST is still active from the
// October 1999 transition, it reports offset=570 (just the 9:30 base) with
// save=0. The inconsistency is evident: it returns abbrev="ACDT" (daylight
// time) but the offset and save values indicate standard time. The AN rules
// clearly show DST should be active until the last Sunday of March 2000.
//
// Compile: g++ -std=c++20 -o gcc_dst_bug gcc_libstdcxx_dst_bug.cpp
// Expected: 630 (10:30 = 9:30 base + 1:00 DST)
// Actual:   570 (9:30 = base only, DST missing)

#include <chrono>
#include <iostream>

int main() {
  using namespace std::chrono;
  auto* tz = locate_zone("Australia/Broken_Hill");
  auto info = tz->get_info(sys_days{2000y / February / 29d} + 23h + 23min + 23s);
  std::cout << duration_cast<minutes>(info.offset).count() << "\n";
}

@rok rok marked this pull request as ready for review December 23, 2025 18:46
@rok
Copy link
Member Author

rok commented Dec 23, 2025

@pitrou

@rok rok changed the title GH-48593: [Draft][C++] C++20: use standard calendar / timezone APIs GH-48593: [C++] C++20: use standard calendar / timezone APIs Dec 23, 2025
@pitrou
Copy link
Member

pitrou commented Jan 5, 2026

It seems that std::chrono on GCC (14.3.0, 15.2.0) potentially has a bug that triggers some of our tests.

Is the bug reported somewhere? If not, can you do that?

@pitrou
Copy link
Member

pitrou commented Jan 5, 2026

We possibly have tzdb download set up in CI too and should update it appropriately.

Yes, I think we should do so. There are also a bunch of code snippets in the C++ and Python codebase that could be removed, IIRC.

@rok
Copy link
Member Author

rok commented Jan 5, 2026

Is the bug reported somewhere? If not, can you do that?

It seems to be related to a known issue, I added comment explaining our case.

@github-actions github-actions bot added awaiting changes Awaiting changes awaiting change review Awaiting change review and removed awaiting committer review Awaiting committer review awaiting changes Awaiting changes labels Jan 5, 2026
@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jan 5, 2026
@github-actions github-actions bot added the awaiting change review Awaiting change review label Feb 10, 2026
@raulcd
Copy link
Member

raulcd commented Feb 11, 2026

@github-actions crossbow submit -g python

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 11, 2026
@github-actions
Copy link

Revision: 4c5113f

Submitted crossbow builds: ursacomputing/crossbow @ actions-e83bbadd74

Task Status
example-python-minimal-build-fedora-conda GitHub Actions
example-python-minimal-build-ubuntu-venv GitHub Actions
test-conda-python-3.10 GitHub Actions
test-conda-python-3.10-hdfs-2.9.2 GitHub Actions
test-conda-python-3.10-hdfs-3.2.1 GitHub Actions
test-conda-python-3.10-pandas-1.3.4-numpy-1.21.2 GitHub Actions
test-conda-python-3.11 GitHub Actions
test-conda-python-3.11-dask-latest GitHub Actions
test-conda-python-3.11-dask-upstream_devel GitHub Actions
test-conda-python-3.11-hypothesis GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.11-spark-master GitHub Actions
test-conda-python-3.12 GitHub Actions
test-conda-python-3.12-cpython-debug GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-1.26 GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.13 GitHub Actions
test-conda-python-3.13-pandas-nightly-numpy-nightly GitHub Actions
test-conda-python-3.13-pandas-upstream_devel-numpy-nightly GitHub Actions
test-conda-python-3.14 GitHub Actions
test-conda-python-emscripten GitHub Actions
test-debian-13-python-3-amd64 GitHub Actions
test-debian-13-python-3-i386 GitHub Actions
test-fedora-42-python-3 GitHub Actions
test-ubuntu-22.04-python-3 GitHub Actions
test-ubuntu-22.04-python-313-freethreading GitHub Actions
test-ubuntu-24.04-python-3 GitHub Actions

Co-authored-by: Raúl Cumplido <raulcumplido@gmail.com>
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 11, 2026
@raulcd
Copy link
Member

raulcd commented Feb 11, 2026

@github-actions crossbow submit wheel-windows-*

@github-actions
Copy link

Revision: cde409e

Submitted crossbow builds: ursacomputing/crossbow @ actions-be2cb464a0

Task Status
wheel-windows-cp310-cp310-amd64 GitHub Actions
wheel-windows-cp311-cp311-amd64 GitHub Actions
wheel-windows-cp312-cp312-amd64 GitHub Actions
wheel-windows-cp313-cp313-amd64 GitHub Actions
wheel-windows-cp313-cp313t-amd64 GitHub Actions
wheel-windows-cp314-cp314-amd64 GitHub Actions
wheel-windows-cp314-cp314t-amd64 GitHub Actions

@raulcd
Copy link
Member

raulcd commented Feb 11, 2026

@github-actions verify-rc-source-windows

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 11, 2026
Copy link
Member

@raulcd raulcd left a comment

Choose a reason for hiding this comment

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

Sorry for being the bearer of bad news but the Windows wheels failures are related:

 >       check_example_file(path, table, need_fix=True)

Python310\lib\site-packages\pyarrow\tests\test_orc.py:145: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Python310\lib\site-packages\pyarrow\tests\test_orc.py:101: in check_example_file
    table = orc_file.read()
Python310\lib\site-packages\pyarrow\orc.py:187: in read
    return self.reader.read(columns=columns)
pyarrow/_orc.pyx:374: in pyarrow._orc.ORCReader.read
    ???
pyarrow/error.pxi:155: in pyarrow.lib.pyarrow_internal_check_status
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   pyarrow.lib.ArrowException: Unknown error: Time zone file /usr/share/zoneinfo/America/Los_Angeles does not exist. Please install IANA time zone database and set TZDIR env.

pyarrow/error.pxi:92: ArrowException

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 12, 2026
@rok
Copy link
Member Author

rok commented Feb 12, 2026

@github-actions crossbow submit wheel-windows-cp314-cp314t-amd64

@github-actions
Copy link

Revision: 7e49c63

Submitted crossbow builds: ursacomputing/crossbow @ actions-e400d8f35f

Task Status
wheel-windows-cp314-cp314t-amd64 GitHub Actions

@rok
Copy link
Member Author

rok commented Feb 12, 2026

@github-actions crossbow submit wheel-windows-cp314-cp314t-amd64

@github-actions
Copy link

Revision: 54017ee

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

Task Status
wheel-windows-cp314-cp314t-amd64 GitHub Actions

@rok
Copy link
Member Author

rok commented Feb 12, 2026

@github-actions crossbow submit wheel-windows-*

@github-actions
Copy link

Revision: 54017ee

Submitted crossbow builds: ursacomputing/crossbow @ actions-b3fc0a238b

Task Status
wheel-windows-cp310-cp310-amd64 GitHub Actions
wheel-windows-cp311-cp311-amd64 GitHub Actions
wheel-windows-cp312-cp312-amd64 GitHub Actions
wheel-windows-cp313-cp313-amd64 GitHub Actions
wheel-windows-cp313-cp313t-amd64 GitHub Actions
wheel-windows-cp314-cp314-amd64 GitHub Actions
wheel-windows-cp314-cp314t-amd64 GitHub Actions

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 12, 2026
@rok rok requested a review from pitrou February 12, 2026 16:50
@rok
Copy link
Member Author

rok commented Feb 12, 2026

@jonkeane in light of CRAN build issues are we ok to merge here?

@jonkeane
Copy link
Member

jonkeane commented Feb 12, 2026

@jonkeane in light of CRAN build issues are we ok to merge here?

I wish we had a way of testing more reliably on the older macOS framework. What's in #49221 (comment) I'm not really comfortable merging to main, but does exercise the code path.

There's at least one other place we need to clean up on main already #49223 so maybe it's fine to merge this and when we get a better way to test this manualy or in CI we'll need to revert this or add a work around. I don't want worries about CRAN to totally slow down everything C++(20) related, but there is a bit of an annoying place we are in!

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.

8 participants