Fix incorrect date offset calculation in rust#918
Merged
Secrus merged 1 commit intopython-pendulum:masterfrom Sep 18, 2025
Merged
Fix incorrect date offset calculation in rust#918Secrus merged 1 commit intopython-pendulum:masterfrom
Secrus merged 1 commit intopython-pendulum:masterfrom
Conversation
Co-authored-by: Holly <holly@dejawu.me>
CodSpeed Performance ReportMerging #918 will not alter performanceComparing Summary
|
Secrus
approved these changes
Sep 18, 2025
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.
Description
Fixes #916
I dug into the rust parsing code a bit and saw that the ordinal calculation might be why 2026W36 was getting the error
ValueError: day is out of range for month. 2026W36 should be August 31, 2026, which becomes ordinal day 243.Looking at the
MONTHS_OFFSETSfor non-leap year (2026):[0]==-1, [1]==0, [2]==31, [3]==59, [4]==90, [5]==120, [6]==151, [7]==181, [8]==212, [9]==243, [10]==273, [11]==304, [12]==334, [13]==365
The original loop:
for i in 1..14:Since 243 < 243 is false, it continues to:
At this point, the original code would execute:
So: day = 243 - MONTHS_OFFSETS[0][9] = 243 - 243 = 0
This gives us month=9, day=0, which is September 0th - an invalid date, hence the "day is out of range for month" error.
Changing the comparison to be
<=means that September (9) is matched appropriately as the month offset, so when it becomes 1-based withlet month = (i - 1) as u32;, it becomes August once more.I added a new test case for this as well in order to verify the functionality! I'm no rust expert though so this may be completely off base 😅
Shoutout to @d3jawu for helping walk me through some of the rust pieces 😊
Pull Request Check List