fix: parse offset seconds in FromStr so Display round-trips#1801
Open
nvxbug wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1801 +/- ##
=======================================
Coverage 90.01% 90.01%
=======================================
Files 35 35
Lines 13831 13855 +24
=======================================
+ Hits 12450 12472 +22
- Misses 1381 1383 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
I'm going to stop responding to these PRs for edge case bugs. There are probably a lot more; you should direct your efforts towards other implementations. |
Contributor
Author
|
Makes sense, I'll redirect to other things. Happy to close this if you'd rather not keep it on the pile, otherwise it's here if the round-trip ever matters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FixedOffset's Display and Debug print a sub-minute offset as +HH:MM:SS, for example +00:00:30, but scan::timezone_offset only reads +HH:MM. That scanner backs FromStr for both FixedOffset and DateTime (through parse_rfc3339_relaxed), so a value chrono prints cannot be parsed back: DateTime::from_str rejects its own to_string() with TooLong on the trailing :SS, and FixedOffset::from_str silently drops the seconds and returns a truncated offset.
The fix teaches timezone_offset to consume an optional seconds component behind a new allow_seconds flag, applying the sign inside the scanner so negative offsets like -00:00:30 stay correct, and turns it on only for the two FromStr paths. Keeping it in the scanner fixes both round-trips in one place while strict parse_from_rfc3339, parse_from_rfc2822, and the %z family keep rejecting seconds. Regression tests cover the FixedOffset and DateTime paths across positive and negative sub-minute offsets.