Repository navigation
GH-54534: [C++] Fix truncation of sub-minute UTC offsets when formatting and parsing zoned timestamps #54684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6018,11 +6018,12 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt, | |
| os.setstate(ios::failbit); | ||
| return os; | ||
| } | ||
| auto m = duration_cast<minutes>(*offset_sec); | ||
| auto neg = m < minutes{0}; | ||
| m = date::abs(m); | ||
| auto abs_sec = date::abs(*offset_sec); | ||
| auto m = duration_cast<minutes>(abs_sec); | ||
| auto neg = *offset_sec < std::chrono::seconds{0}; | ||
| auto h = duration_cast<hours>(m); | ||
| m -= h; | ||
| auto s = abs_sec - duration_cast<std::chrono::seconds>(duration_cast<minutes>(abs_sec)); | ||
| if (neg) | ||
| os << CharT{'-'}; | ||
| else | ||
|
|
@@ -6035,6 +6036,14 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt, | |
| if (m < minutes{10}) | ||
| os << CharT{'0'}; | ||
| os << m.count(); | ||
| if (s != std::chrono::seconds{0}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if a user calls Arrow’s strftime function with %z? The vendored date library defines %z as +/-hhmm and %Ez as +/-hh:mm, truncating offsets that include seconds. This change instead returns +000921 or +00:09:21. Please avoid changing the format contract and handle sub-minute offsets in the timestamp-to-string cast, for example by formatting these values in UTC as suggested in #54534. |
||
| { | ||
| if (modified != CharT{}) | ||
| os << CharT{':'}; | ||
| if (s < std::chrono::seconds{10}) | ||
| os << CharT{'0'}; | ||
| os << s.count(); | ||
| } | ||
| command = nullptr; | ||
| modified = CharT{}; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%Ezis now recognized here and inStrptimeTimestampParser, butStrftime::Makestill checks only%zand%Zwhen the input has no timezone. This means%Ezis treated as UTC while%zis rejected. Please use the same format check in both paths and add tests for%Ezwith and without a timezone.