ShivanshhhG opened a new pull request, #54627:
URL: https://github.com/apache/arrow/pull/54627

   ### 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.
   
   * GitHub Issue: #54534


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to