Skip to content

GH-54534: [C++] Fix truncation of sub-minute UTC offsets when formatting and parsing zoned timestamps - #54627

Closed
ShivanshhhG wants to merge 1 commit into
apache:mainfrom
ShivanshhhG:fix-54534-zoned-timestamp-seconds-offset
Closed

ShivanshhhG wants to merge 1 commit into
apache:mainfrom
ShivanshhhG:fix-54534-zoned-timestamp-seconds-offset

Conversation

@ShivanshhhG

Copy link
Copy Markdown

Rationale for this change

When formatting zoned timestamps whose UTC offset includes sub-minute seconds (e.g. historical IANA zones such as Africa/Monrovia prior to 1972 at UTC-00:44:30 or Europe/Paris prior to 1911 at UTC+00:09:21), the vendored date.h library truncated the offset to whole minutes via duration_cast<minutes>, omitting the remaining seconds and emitting an inaccurate offset (e.g. -0044 instead of -004430). When parsed back (via Cast or CSV reader), the timestamp instant was shifted by up to 59 seconds.

What changes are included in this PR?

  1. cpp/src/arrow/vendored/datetime/date.h:

    • In to_stream for format specifiers %z and %Ez, check whether *offset_sec has non-zero seconds (s != 0).
    • If non-zero seconds are present, emit them (±hhmmss for %z or ±hh:mm:ss for %Ez). If whole minutes, retain the standard ±hhmm / ±hh:mm representation.
  2. cpp/src/arrow/util/value_parsing.h:

    • Added detail::ParseHHMMSS to parse 6-digit offsets with hours, minutes, and seconds.
    • Updated ParseTimestampISO8601 to recognize and parse [+-]HHMMSS and [+-]HH:MM:SS zone offsets.
  3. cpp/src/arrow/util/value_parsing.cc & cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc:

    • Updated StrptimeTimestampParser and GetZone to recognize %Ez as providing a zone offset.
  4. Tests:

    • Added unit test cases for sub-minute offsets and invalid offsets in cpp/src/arrow/util/value_parsing_test.cc.
    • Added regression test cases casting zoned timestamps in Africa/Monrovia and Europe/Paris to strings in cpp/src/arrow/compute/kernels/scalar_cast_test.cc.

Are these changes tested?

Yes, new unit tests were added to value_parsing_test.cc and scalar_cast_test.cc.

Are there any user-facing changes?

Yes, casting zoned timestamps with sub-minute UTC offsets to string (and exporting them to CSV) now accurately formats the offset seconds rather than truncating them, and ParseTimestampISO8601 can parse timestamps with seconds in the UTC offset.

…ormatting and parsing zoned timestamps

When formatting zoned timestamps whose UTC offset includes sub-minute seconds (e.g. historical IANA zones like Africa/Monrovia prior to 1972 at UTC-00:44:30 or Europe/Paris prior to 1911), the vendored date.h library truncated the offset to whole minutes via duration_cast<minutes>, dropping the remaining seconds and emitting an inaccurate offset (e.g. -0044 instead of -004430). When parsed back, the timestamp was shifted by up to 59 seconds.

This patch:
1. Updates date.h %z and %Ez formatters to format seconds when the UTC offset contains non-zero seconds (±hhmmss or ±hh:mm:ss).
2. Updates ParseTimestampISO8601 in value_parsing.h to recognize and parse [+-]HHMMSS and [+-]HH:MM:SS zone offsets.
3. Recognizes %Ez as providing a zone offset in StrptimeTimestampParser and GetZone.
4. Adds regression unit tests in value_parsing_test.cc and scalar_cast_test.cc.

Closes apache#54534.

Signed-off-by: SHIVANSH-ux-ys <singaser78@gmail.com>
@github-actions github-actions Bot added the awaiting review Awaiting review label Oct 19, 2026
@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

This pull request has been automatically closed because you currently have 4 open pull requests, which is more than the limit of 3.

Due to the increase in pull requests opened by AI bots, and in order to keep the review queue manageable, Apache Arrow limits contributors without repository access to at most 3 concurrently open pull requests. This helps make sure each pull request gets the attention it needs and that work in progress does not go stale.

Once one of your other open pull requests has been merged or closed, you are welcome to reopen this one.

See also:

@github-actions github-actions Bot closed this Oct 19, 2026
@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #54534 has no components, please add labels for components.

@ShivanshhhG

Copy link
Copy Markdown
Author

Closed stale PR #51133 so concurrent open PR count is now <= 3. Reopening this PR for review. Thank you!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant