Repository navigation
fix(expand): MONTHLY month days on their grid, RFC-checked candidates - #43
Merged
Merged
Conversation
A MONTHLY;BYMONTHDAY rule without BYDAY whose start month holds none of the listed days sent ical.js' setup into a search that reads the list before normalising it to the month: -31 in a June became day 0, rolled into May, and every later month came one month early. A call with `from` moved the start into another month and got another grid, so INTERVAL=5;BYMONTHDAY=31,-31 from 30 June 1992 gave July and December of 2026 without `from` and March and August with it. RFC 5545 gives March and August. The same search gave up after three months, so BYMONTHDAY=31;INTERVAL=5 from a June had no occurrence at all, reported complete, and it yielded a start month that BYMONTH leaves out. recurIterator now sets such a rule up on day 1 of the first month on ical.js' own grid that the rule takes and that holds a listed day, at the earliest time of day an instance has, or marks it empty when no month in a 400-year cycle does. That takes ical.js' exact setup branch, so a moved start keeps the grid too, and no exclusion list is needed. The walk had a second defect in such months: with a BYHOUR, BYMINUTE or BYSECOND list, next_month stepped the next time on day 1 of a month without the day and reported it (BYMONTHDAY=31;BYHOUR=0,23 gave 1 February at 23:00), so the result depended on the months a walk passed. A step that lands on an unlisted day now ends the day instead. Tests check these rules against a brute-force RFC 5545 expansion and, with `from`, against the filtered result. Closes #42 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ical.js ends a MONTHLY rule after 336 months without an instance and a YEARLY one after 28 years. Since 0.8.0 that is reported as stoppedBy 'library', which is right where instances follow the gap (a fifth Sunday of February, 40 years apart) but wrong for a rule that never recurs: FREQ=MONTHLY;INTERVAL=2;BYDAY=5MO;BYSETPOS=5 asks for the fifth of a set of at most one day, and dav-mcp then marks a correct series incomplete. holdsInstance counts, per RFC 5545, whether any period after the last instance ical.js gave, up to the end of the range, holds one. Month lengths and weekdays repeat every 400 years, so one cycle of periods settles it. Only where it proves none is the give-up taken as the rule's end; BYWEEKNO and an ordinal weekday under BYMONTHDAY or BYYEARDAY are not counted and stay 'library' (fail closed). A property test checks the count against the brute-force RFC 5545 expansion. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Built on the box in node:22 from the two commits before; CI checks that dist equals a fresh build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The never-recurs check looked at 4,800 months of the rule's grid, but the grid returns to the same calendar position only after lcm(months per period, 4,800) months. YEARLY;INTERVAL=7;BYMONTH=2; BYMONTHDAY=29;BYDAY=MO from 2001 has a Monday 29 February in 2596 and next in 3408, 116 periods later; after 57 periods the check called the rule ended and the expansion complete. It now counts 4,800 / gcd(months per period, 4,800) periods, the least number after which every period shape has come round (proof in cyclePeriods). The count is charged to the expansion's budget, one unit a month, as measured (4,800 months take 1.3 to 4.6 ms). The RFC 5545 reading of a period moves into periodModel, which the next commit uses as well. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since the previous fixes call more results complete, the candidates ical.js yields that are no instance matter more. Its MONTHLY setup yields the day it finds untested (BYDAY=5MO;BYSETPOS=2 gave the fifth Monday of DTSTART's month; BYMONTH=6;BYDAY=1MO a December's first Monday). With BYMONTH it steps every listed month whatever INTERVAL says, and with BYMONTHDAY and no BYDAY it never reads BYSETPOS. Each is a superset of the instances, so every MONTHLY candidate is now checked against the RFC 5545 period model and dropped if it is no instance. COUNT then counts instances only, and a stretch of a whole cycle without one ends the rule. ical.js also tested the 1st of each new month only against BYSETPOS position 1, so BYDAY=SA;BYSETPOS=-5 never gave 1 August 2020. The 1st is now kept when BYSETPOS names it from the back. Where ical.js is no superset, the rule is left as it gives it (tsdav-utils#36): BYDAY with BYMONTHDAY, BYDAY with BYSETPOS and several times of day, BYMONTH with a fifth weekday, and YEARLY rules. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ical.js 2.2.1 sets up a MONTHLY rule with a fifth or fifth-last weekday that DTSTART's month lacks by stepping on month by month until one has it, without a bound. FREQ=MONTHLY;INTERVAL=24;BYDAY=-1TH,5MO from February 2019 visits only Februaries of odd years, none with five Mondays, so the RecurIterator constructor never returns: a calendar object with such a rule hangs the process outside any budget (0.8.0 too). The widened RFC 5545 property test found it. recurIterator emulates that search for one 400-year cycle before constructing the iterator and refuses the rule when no month on the iteration's steps has the weekday, as ical.js refuses other rules it cannot set up. Refused with `from` as without it. The RFC property leaves fifth weekdays out: their setup search also loses first instances (tsdav-utils#36); fixed cases cover the days it invents. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Built on the box in node:22 from the commits before; CI checks that dist equals a fresh build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
holdsInstance proves that a rule has nothing left to give, but that only settles the result where what ical.js gave is trusted. With BYSETPOS, ical.js invents days where its candidates are not checked against RFC 5545: YEARLY;INTERVAL=7;BYDAY=5TU;BYSETPOS=2 gives a fifth Tuesday every seven years, RFC 5545 none (#36). So holdsInstance now counts a BYSETPOS rule only where keepInstances checks every candidate (shared predicate candidatesChecked); elsewhere a give-up stays 'library'. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI checks that dist equals a fresh build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fifth-weekday guard refused rules ical.js expands: in its MONTHLY BYDAY setup, init skips the forward search for a weekday the start month lacks once an earlier BYDAY entry found a day in that month (INTERVAL=24;BYDAY=1MO,5TU from 2019-02-04 is valid). It also refused a rule with no instance at all, which RFC 5545 reads as DTSTART only. byDaySetupEndless now follows init step by step: BYDAY sorted by sort_byday_rules (WKST), nthWeekDay counted from Sunday, the daysInMonth variable it carries across entries, the skip, and increment_month with BYMONTH's shared position. A search not done after 4,800 steps never is. Only then is ical.js not set up: a rule holdsInstance proves empty gets an ended iterator (complete, DTSTART only), any other is refused as before (1SA,5TU from 2025-02-23 with INTERVAL=24 hangs ical.js). holdsInstance reads a period's year within the 400-year cycle near 2000, so a long reach stays inside Date's range. Co-Authored-By: Claude Opus 5.5 <[email protected]>
YEARLY results were still called complete with days ical.js invents: BYMONTH=2;BYMONTHDAY=30 from 2019-01-30 gave 2 March 2019, 1 March 2020 and so on, where RFC 5545 has no instance. And where ical.js reads a rule differently it may skip instances, which no check saw. keepInstances now checks MONTHLY and YEARLY candidates against the RFC 5545 period model and drops non-instances (COUNT counts instances only, as for MONTHLY). It also compares each period the iteration passes with the model's instances from its start; one ical.js never yielded is recorded, and the walk asks for those in [from, the end it stands for] and then reports stoppedBy 'library'. So a complete result is RFC 5545's: a YEARLY BYMONTHDAY without BYMONTH (ical.js reads DTSTART's month only) or a MONTHLY BYDAY with BYMONTHDAY (stepped whatever INTERVAL says) now says library instead of complete. Such a YEARLY rule is no longer worked out by fixedYearlyWalls, which followed ical.js' reading. With every modelled rule checked, the never-recurs count no longer needs the BYSETPOS restriction of 9848eaf. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Built on the box in node:22; CI checks that dist equals a fresh build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The YEARLY sweep against the review's RFC 5545 oracle still found complete results that differ from it, all with COUNT or `from`: - ical.js counts what it yields, and twice where it retries a candidate inside next(), which the drop compensation did not cover: a COUNT ended one instance early, reported complete. - an instance ical.js skipped shifts every later count, but the walk only asked for misses from `from` on, and kept the shifted occurrences after the miss in a library result. - a rule ical.js sets up at DTSTART to yield nothing skipped the walk with `from`, and with it the check for instances it missed. keepInstances now switches ical.js' count off and counts the kept instances itself (countReached ends the rule). The walk asks for misses from DTSTART where the rule has COUNT, removes what it added after the first miss, and walks a rule set up empty from DTSTART, which ends at once and runs the check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Built on the box in node:22; CI checks that dist equals a fresh build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
At 1,500 runs seed 1 draws YEARLY;BYMONTHDAY=30,31,-31,-1;BYMONTH=11,10,3,
two of whose days fall on one date: ical.js refuses it ("Same occurrence
found twice"), as 0.8.0 does. The property now requires the same
refusal with `from` instead of failing.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The sweep tolerated any message matching "Invalid", which also matches the package's own new refusal, so a new false refusal could pass unnoticed. Refs #42 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Four tests asserted wall time (100 ms to 1 s). On a loaded runner one of them failed at 202 ms on Node 20 although nothing was slow. They now count what they guard: Intl lookups for the zone scan, ical.js rule steps for the hostile VTIMEZONE, and the metered expansion steps against WORK_BUDGET. Each still fails if the guarded scan or walk comes back unbounded. Refs #42 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
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.
What
Fixes to
expandOccurrencesfor MONTHLY rules whose months may hold none of the rule's days (#42), for rules ical.js gives up on, and for candidates ical.js yields that RFC 5545 rules out. Every claim below is checked against a brute-force RFC 5545 expansion (test/rfcOracle.ts).#42.
FREQ=MONTHLY;INTERVAL=5;BYMONTHDAY=31,-31from 30 June 1992 gave July/December 2026 withoutfromand March/August with it. RFC 5545 gives March and August. ical.js' setup, in a start month without a listed day, searched on with the BYMONTHDAY list not yet normalised. If the second listed value is negative and longer than the month (-31in June), that gives day 0, which rolls into 31 May, so the whole grid runs a month early. A moved start lands in another month and gets another grid. The same search gave up after three months, which lost rules likeBYMONTHDAY=31;INTERVAL=5from a June entirely, reported complete. The iteration is now set up in the first month on its own grid that holds a listed day, at the earliest time of day an instance has. That is ical.js' exact setup branch, so no exclusion list is needed.Release notes: behaviour changes, also without
fromBYMONTHDAY=31;INTERVAL=5from a June: 31 July 1994, …).BYMONTHDAY=31;BYHOUR=0,23no longer yields 1 February and 1 April at 23:00.stoppedBy: 'library'. Each period the iteration passes is compared with RFC 5545's instances. So a complete result is RFC 5545's, or it says it is not. COUNT counts the kept instances; with a skipped instance, a COUNT result stops at the first one it missed:INTERVAL=7;BYDAY=5MO;BYSETPOS=2from 1993-05-08 no longer yields 1993-05-31,BYDAY=5MO;BYSETPOS=5from 2001-01-01 no longer yields 2001-01-29, andBYMONTH=6;BYDAY=1MOfrom a December no longer yields that December;INTERVAL=24;BYMONTHDAY=-2,28;BYMONTH=11;COUNT=1from 2007-05-28T01:59 gives DTSTART only (0.8.0: plus 2007-11-28), andINTERVAL=2;BYMONTH=1,2,3,4gives January and March, no longer every listed month;BYMONTHDAY=31,30;BYMONTH=7,4,10,1;BYSETPOS=3gives none (0.8.0: every 30th and 31st).BYMONTH=2;BYMONTHDAY=30from 2019-01-30 gives DTSTART only (0.8.0: 2 March 2019, 1 March 2020, …, complete).'library'instead of complete, because ical.js skips instances: YEARLY BYMONTHDAY without BYMONTH (RFC 5545 takes every month, ical.js DTSTART's only, e.g.YEARLY;BYMONTHDAY=15), MONTHLY BYDAY with BYMONTHDAY and INTERVAL > 1, YEARLY BYSETPOS (ical.js reads it per month), BYMONTH with a fifth weekday. Such a YEARLY rule is no longer worked out by the fixed-day arithmetic, which followed ical.js.BYDAY=SA;BYSETPOS=-5now gives 1 August 2020.stoppedBy: 'library'. Example:MONTHLY;INTERVAL=2;BYDAY=5MO;BYSETPOS=5asks for the fifth of at most one Monday, which never comes. Each period after the last instance, up to the range's end, is counted against RFC 5545 for one full cycle of the rule's own periods: 4,800 / gcd(months per period, 4,800), after which month lengths and weekdays have come round. The count is charged to the budget at one unit a month (measured 1.3–4.6 ms for 4,800 months). Rules that ical.js gives up on while instances exist stay'library', e.g.YEARLY;INTERVAL=7;BYMONTH=2;BYMONTHDAY=29;BYDAY=MOfrom 2001, whose next instance after 2596 is in 3408. So do shapes it cannot count (BYWEEKNO; an ordinal weekday under BYMONTHDAY/BYYEARDAY).init. Where it would never end, ical.js is not set up. A rule with no instance at all gives DTSTART alone, complete:INTERVAL=24;BYDAY=5MOfrom February 2019. A rule with instances that ical.js cannot set up is refused as an invalid rule, withfromas without, where 0.8.0 never returned:INTERVAL=24;BYDAY=-1TH,5MOfrom 2019-02-14,INTERVAL=24;BYDAY=1SA,5TUfrom 2025-02-23. Rules where the search is skipped are expanded:INTERVAL=24;BYDAY=1MO,5TUfrom 2019-02-04.Not checked, as ical.js gives them (tsdav-utils#36): BYWEEKNO, an ordinal weekday under BYMONTHDAY or BYYEARDAY (RFC 5545 leaves its scope open), and COUNT read as ical.js counts it (DTSTART aside). FREQ below MONTHLY is unchanged.
dav-mcp: after the release, its test "a fifth Monday by BYSETPOS=5 … is incomplete, not empty" (PR #174) has to expect complete again.
stoppedBy: 'library'. ical.js drops all but one hour there, e.g.YEARLY;BYMONTH=6;BYDAY=MO;BYHOUR=0,9from 2021-06-07T00:00 yields only the 00:00 instances (8 of 16). 0.8.0 called that result complete; it is now flagged, so consumers see it as truncated.Tests
Box, node:22 (workdir w134), on the code of f7259ac (dist built there). CI is green on Node 18–26.
expandFrom+monthEnd+recurOrderat 1,500 runs, seeds 2–4 green. Seed 1's only failure was an ical.js refusal in the month-end property, which 0.8.0 shares; it is now accepted whenfromrefuses alike (f7259ac, rechecked locally on seeds 1 and 3).fromeach): 1,509 complete and all equal to RFC 5545; 491'library'with no non-instance in them;from4,527 of 4,527 match; 227fromcalls complete in a window the full walk could not vouch for, all equal to RFC 5545 there.'library'.completeholds per window: a library result can be complete for a laterfrom, because a miss before the window does not touch it. Errors appear only where ical.js refuses as in 0.8.0.frommismatches.expandFrom300 runs 40.2 s on 0.8.0, 44.2 s on this PR.No version bump; dist rebuilt on the box (node:22).
Closes #42
🤖 Generated with Claude Code