← Back to Pull requests

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

Open
unknown opened this pull request with 338 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 20, 2026 05:17 UTC
Author

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), formatting with %z would truncate the offset to whole minutes, dropping remaining seconds and causing instant drift. To preserve instant fidelity without violating the %z / %Ez formatting contract (whole minutes ±HHMM / ±HH:MM), timestamps with sub-minute offsets are formatted in UTC (...Z) during timestamp-to-string cast. Additionally, ParseTimestampISO8601 is updated to support parsing 6-digit sub-minute offsets ([+-]HHMMSS and [+-]HH:MM:SS), and %Ez is recognized across Strftime and GetZone.

What changes are included in this PR?

1. cpp/src/arrow/compute/kernels/scalar_cast_string.cc: In ConvertZoned, if a timestamp instant has non-zero sub-minute seconds (offset % 60 != 0), format it in UTC (...Z) to preserve the exact stored instant without violating the %z minute contract. Fixed-offset zones (OffsetZone) and UTC take the fast path without redundant get_info() calls.
2. cpp/src/arrow/util/value_parsing.h: Add detail::ParseHHMMSS and update 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: Unify zone format validation in Strftime::Make and GetZone via FormatHasZone to recognize %Ez alongside %z and %Z, properly rejecting %Ez when the input timestamp has no timezone.
4. cpp/src/arrow/compute/kernels/scalar_cast_test.cc: Add round-trip tests across all four timestamp units (s, ms, us, ns) for historical sub-minute zones (Africa/Monrovia and Europe/Paris), verifying cast to string and back to UTC matches the exact stored value.
5. cpp/src/arrow/compute/kernels/scalar_temporal_test.cc & cpp/src/arrow/util/value_parsing_test.cc: Add unit tests for %Ez (with and without timezones) and sub-minute offset parsing/validation bounds.

Are these changes tested?

Yes, covered by unit tests in scalar_cast_test.cc, scalar_temporal_test.cc, and value_parsing_test.cc.

Are there any user-facing changes?

  • Casting zoned timestamps with historical sub-minute UTC offsets to string formats them in UTC (...Z), preventing truncation errors and preserving round-trip instant accuracy.

  • Timestamp parsing now supports ISO8601 strings with 6-digit offsets ([+-]HHMMSS and [+-]HH:MM:SS).

  • strftime now recognizes %Ez and validates timezone presence identically to %z and %Z.
  • GitHub Issue: #54534
  • Diff: 338 lines (+253 / -85) across 4 files Reviewer: ShivanshhhG Review duration: 60842m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.49) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.49 · 338 lines diff across 4 files
    0.49
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.349
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #54684"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.2% (MEDIUM) · Higher = larger blast radius
    49.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.1% · Safe to merge
    29.1%
    Repository