Repository navigation
Conversation
make_time guessed a month and day from yday ((yday-1).divmod(31)), which is
often not a real date (e.g. Feb 31). With a zone, apply_offset then moved
that invalid date and lost the overflow, so a late time with a negative
offset could end up days off:
Time.strptime("1985-062 14:58:14 -1130", "%Y-%j %H:%M:%S %z")
# => 1985-03-06 14:58:14 -1130, expected 1985-03-03
Walk the months with month_days to get the real month and day instead.
This branch has not been deployed
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.
Time.strptimewith%jand an offset can land on the wrong day:The cause is in
make_time: it first guessesmon, day = (yday-1).divmod(31), which is often not a real date (day 62 → Feb 31). With a zone,apply_offsetthen moves that date, and when the day goes past the end of the month it resets to day 1 and loses the overflow. The diff/retry step can't recover from that.This walks the months with
month_daysto get the real month and day, and then callsmake_timeonce. When there's no year it uses the same year the rest ofmake_timewould take fromnow. Day 366 in a common year still raisesArgumentError.Checked 60k random
%Y-%j/%j %Ystrings (with and without%z/%:z, offsets -12:00..+14:45, years 1901-2100) againstDateTime.strptime: master gets 95 wrong, this PR 0, with TZ set to UTC, America/New_York and Pacific/Chatham.Added
test_strptime_j_with_offset(fails on master).rake testpasses with TZ=UTC, America/New_York, Asia/Tokyo and Pacific/Chatham.Note: #91 sends ISO week dates through this same yday path, so it hits this too (left a comment there).