Fix rrule byweekno for days in the previous year's last ISO week - #1537
Open
vineethsaivs wants to merge 1 commit into
Open
Fix rrule byweekno for days in the previous year's last ISO week#1537vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
The first days of a year can belong to the last ISO week of the previous year. _iterinfo.rebuild() derived that last week number from the current year's length (self.yearlen / no1wkst) with a hardcoded 52, instead of the previous year's length, so it was off by one in some years. For example byweekno=52 skipped 2011-01-01/02 and byweekno=53 wrongly included them, even though those days are ISO week 52 of 2010 (which has no week 53). Compute the previous year's week count the same way the current-year block already does (divmod on the week-adjusted length), using the previous year's lyearlen and lno1wkst. A byweekno-vs-date.isocalendar cross-check over 1998-2034 now matches for every week, and the full rrule suite is unchanged.
vineethsaivs
force-pushed
the
fix/rrule-byweekno-prev-year-weeks
branch
from
July 15, 2026 22:54
5fcc5dc to
993c2ff
Compare
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.
Summary
rrule(..., byweekno=...)misattributes the first days of a year that actually belong to the last ISO week of the previous year._iterinfo.rebuild()computeslnumweeks, the last week number of the previous year, to decide whether early-January spillover days should be marked for a givenbyweekno. It computed that value from the current year's length with a hardcoded52:The parallel current-year block a few lines above already does it correctly, using
divmodon the week-adjusted length. Because the previous-year block used the wrong year's variables (and hardcoded 52 instead of the realdiv),lnumweekscame out one too high in some years.Reproduction
2011-01-01and2011-01-02are ISO week 52 of 2010 (2010 has no week 53), confirmed bydate.isocalendar():Fix
Compute the previous year's week count the same way the current-year block does, from the previous year's
lyearlen/lno1wkst:Validation
testYearlyByWeekNoLastWeekOfPrevYear(fails before, passes after).byweekno=Nagainst Python's owndate.isocalendar()over every week of 1998-2034 had mismatches only in 2011 and 2022 before this change and zero after.tests/test_rrule.pysuite passes: 562 passed, 1 xfailed (the 561 pre-existing tests plus the new regression test). The documentedtestYearlyByWeekNoAndWeekDay53still returns its exact expected values.Includes an
AUTHORS.mdentry and achangelog.dnews fragment.