You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stop ical.js rule quirks from yielding wrong occurrences #36
After #31 (PR #35) ical.js walks BY lists in order, but several of its rule evaluations still produce wrong occurrences while expandOccurrences reports complete: true. Confirmed during #31 and the review of #35 (ical.js 2.2.1):
YEARLY;BYMONTH=2;BYMONTHDAY=30 yields 2026-03-02, 2027-03-02, 2028-03-01: impossible dates become phantom occurrences (RFC 5545: invalid dates are ignored).
MONTHLY with BYDAY and more than one time of day adds a phantom instance on the 1st of the next month.
HOURLY with BYHOUR, and MONTHLY with BYMONTH, ignore INTERVAL.
BYDAY with BYMONTHDAY throws "Malformed values" on valid rules after a fixed 48-step search, e.g. MONTHLY;INTERVAL=3;BYMONTHDAY=13,5,20;BYDAY=TU (fails closed).
Per case: a failing test against an independent expansion, then decide fix location (upstream ical.js with a report, or a guard in tsdav-utils that refuses with a typed error / reports complete: false instead of returning wrong occurrences).
Two more ical.js 2.2.1 defects, found in the review of #39. #39 works around both by walking these rules from DTSTART, so a call with from gives what the call without it gives. ical.js' own result stays as it is.
MONTHLY setup with a fifth or fifth-last weekday. Example: 5SU, from a month that has no fifth Sunday. The setup (init, the MONTHLY BYDAY branch) searches forward with increment_month until a month has that weekday. Each step moves the shared BYMONTH position, and resetting last to the start does not undo it. The setup then yields what it found untested, without BYSETPOS or the contracting rules. So the first instances depend on where the walk began. For example, FREQ=MONTHLY;BYDAY=5SU;BYSETPOS=3,-2 yields a fifth Sunday although BYSETPOS rules out every day.
Years 0 to 99.Time.toUnixTime goes through Date.UTC, which reads those years as 1900 to 1999. So ical.js compares and orders times before the year 100 wrongly, and the walk from such a DTSTART yields nothing past them, or misses some.
One more, from the re-review of #39: ical.js gives a rule up silently.RecurIterator.next ends a YEARLY rule after 28 years without an instance and a MONTHLY one after 336 months, then returns null as if the rule had ended. A fifth Sunday of February can be 40 years away: FREQ=YEARLY;BYMONTH=2;BYDAY=5SU from 2058 stops after 2088 and never yields 2128-02-29. The setup (init) has no such cut: it searches to UNTIL or the year 20000.
#39 detects the give-up (null although COUNT is not reached and UNTIL not passed) and reports complete: false, stoppedBy: 'library'; a write check on such a series fails closed. The occurrences after the cut stay unknown until ical.js is fixed or replaced for these rules.
One more, from the final review of #39: COUNT is counted as ical.js counts it, not as RFC 5545 does, when DTSTART is off the rule. RFC 5545 (3.8.5.3) counts DTSTART as the first instance even where the rule would not produce it. ical.js counts only the instances the rule yields, so the series gets one occurrence more. Example: DTSTART:20580120T130000, RRULE:FREQ=YEARLY;BYMONTH=2;BYDAY=5SU;COUNT=3. RFC: 2058-01-20 plus two fifth Sundays of February. ical.js: 2058-01-20 plus three. tsdav-utils walks COUNT rules from DTSTART in full, with or without from, so both calls agree, but both follow ical.js here.
Three more ical.js 2.2.1 defects, found while fixing #42. All three give the same result with from and without it (so no contract break), but the result is not RFC 5545. Checked against a brute-force RFC 5545 expansion (test/rfcOracle.ts in the #42 PR).
MONTHLY with BYMONTH ignores INTERVAL.increment_month steps through the BYMONTH list and never reads INTERVAL there. FREQ=MONTHLY;INTERVAL=2;BYMONTH=1,2,3,4;BYMONTHDAY=1 from 2026-01-01 yields Jan, Feb, Mar, Apr. RFC 5545: Jan and Mar (every second month, limited to those listed).
MONTHLY BYDAY setup in a month BYMONTH leaves out. The setup (init, MONTHLY BYDAY branch) computes the weekday in DTSTART's month and yields it untested. FREQ=MONTHLY;BYMONTH=6;BYDAY=1MO from 2018-12-01 yields 2018-12-03, a December. The BYMONTHDAY branch had the same leak; the expandOccurrences with from shifts MONTHLY BYMONTHDAY=31,-31 grid #42 fix sets that one up in a listed month, the BYDAY branch is unchanged.
YEARLY BYMONTHDAY.expand_year_days builds a date from each listed day without checking that the month has it: FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30 yields 2 March every year (RFC 5545: never). Without BYMONTH it reads BYMONTHDAY in DTSTART's month only (RFC 5545: every month), so FREQ=YEARLY;BYMONTHDAY=-31 from a November yields nothing and ical.js gives the rule up (reported stoppedBy: 'library' since expandOccurrences with from shifts MONTHLY BYMONTHDAY=31,-31 grid #42's PR, which is the honest verdict there).
Scale, from the #42 sweep (box, 2 seeds × 1,500 rules, date-only, compared with RFC 5545): MONTHLY with BYMONTH and INTERVAL > 1 differs in 260 of 305 rules; YEARLY with a month-end BYMONTHDAY (29, 30, 31, -29, -30, -31) in 389 of 570.
Now handled in #43. Each MONTHLY candidate is checked against RFC 5545 and dropped if it is no instance. COUNT counts only the instances that remain:
MONTHLY with BYMONTH ignores INTERVAL: the off-grid months are dropped.
MONTHLY BYDAY setup in an unlisted month, or with BYSETPOS unread: the untested setup day is dropped (BYDAY=5MO;BYSETPOS=2 from 1993-05-08 gave 1993-05-31).
BYMONTHDAY with BYSETPOS and no BYDAY: ical.js ignores BYSETPOS; the days it does not name are dropped.
The 1st of a month under a negative BYSETPOS: next_month tested a new month's 1st only against position 1, so BYDAY=SA;BYSETPOS=-5 never gave 2020-08-01. That 1st is now kept.
Still open: ical.js here yields no superset of the instances, so dropping candidates cannot fix these:
MONTHLY BYDAY with BYMONTHDAY: _byDayAndMonthDay steps month by month whatever INTERVAL says. FREQ=MONTHLY;INTERVAL=2;BYMONTHDAY=-1,30,29;BYDAY=FR,WE from 2012-12-26 yields January, March, May and so on, never the grid's August 2013 (30 August is a Friday).
MONTHLY BYDAY with BYSETPOS and more than one time of day: ical.js applies BYSETPOS to the days, RFC 5545 to the date-times. FREQ=MONTHLY;BYDAY=MO;BYHOUR=9,10;BYSETPOS=2 from 2026-02-01T09:00 gives 2 Feb (the setup) and 9 Feb, each at 9 and 10, and 1 March at 10:00, a Sunday. RFC 5545 gives the first Monday at 10:00 each month.
MONTHLY with BYMONTH and a fifth weekday (the setup search from the first comment): it loses the first year. FREQ=MONTHLY;BYMONTH=6,9;BYDAY=1SA,5TU;BYSETPOS=1 from 2022-06-08 misses 2022-09-03.
#43 now checks every MONTHLY and YEARLY candidate against RFC 5545 and drops non-instances; COUNT counts the kept instances. It also compares each period ical.js passes with RFC 5545's instances in it. If ical.js skipped one, the result is complete: false, stoppedBy: 'library', and a COUNT result stops at the first skipped instance. So for these frequencies ical.js' defects no longer give a wrong result reported as complete; they give a result that says it is incomplete. The YEARLY sweep against the review's oracle (2,000 rules, 6,000 from calls) finds no complete result that differs.
Still open here, because ical.js cannot give the instances (now reported 'library', no longer wrong-but-complete):
YEARLY BYMONTHDAY without BYMONTH: ical.js reads it in DTSTART's month only; RFC 5545 takes every month (YEARLY;BYMONTHDAY=15).
YEARLY BYMONTHDAY with BYMONTH: ical.js reads negative days by the previous instance's month and skips some.
YEARLY BYDAY with BYMONTH and BYSETPOS: ical.js applies BYSETPOS per month; RFC 5545 applies it to the year.
MONTHLY BYDAY with BYMONTHDAY: _byDayAndMonthDay steps month by month whatever INTERVAL says.
MONTHLY BYDAY with BYSETPOS and several times of day: ical.js applies BYSETPOS to the days, RFC 5545 to the date-times.
Not checked at all: BYWEEKNO, an ordinal weekday under BYMONTHDAY or BYYEARDAY (RFC 5545 leaves the scope open), and COUNT read as ical.js reads it (DTSTART aside, comment above). A fix of the missing instances means computing these rules without ical.js; the period model in src/recur.ts (periodModel) already gives their sets.
Two more, found in the review of PhilflowIO/dav-mcp#174 against an independent RFC 5545 expansion (python-dateutil). Both are returned as complete with no note, on 0.7.0 and 0.8.1 alike:
DTSTART;VALUE=DATE:20250101, RRULE:FREQ=YEARLY;BYWEEKNO=40,2;BYDAY=MO, window 2027-01-05..2027-02-14: every Monday from Jan 11 instead of only Jan 11 (week 2). Correct when DTSTART falls on a matching Monday.
DTSTART:20190102T100000Z, RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=SU,WE;BYSETPOS=-1: includes the Wednesdays (2026-01-21, 02-04, 02-18); RFC 5545 gives only the Sundays (BYSETPOS ignored on WEEKLY).
Like the MONTHLY/YEARLY candidate check in 0.8.1, these need either an RFC check of the candidates for YEARLY+BYWEEKNO and WEEKLY+BYSETPOS, or a 'library' report, never a silent complete.
Activity
PhilflowIO commentedon Nov 18, 2026
Two more ical.js 2.2.1 defects, found in the review of #39. #39 works around both by walking these rules from DTSTART, so a call with
fromgives what the call without it gives. ical.js' own result stays as it is.5SU, from a month that has no fifth Sunday. The setup (init, the MONTHLY BYDAY branch) searches forward withincrement_monthuntil a month has that weekday. Each step moves the shared BYMONTH position, and resettinglastto the start does not undo it. The setup then yields what it found untested, without BYSETPOS or the contracting rules. So the first instances depend on where the walk began. For example,FREQ=MONTHLY;BYDAY=5SU;BYSETPOS=3,-2yields a fifth Sunday although BYSETPOS rules out every day.Time.toUnixTimegoes throughDate.UTC, which reads those years as 1900 to 1999. So ical.js compares and orders times before the year 100 wrongly, and the walk from such a DTSTART yields nothing past them, or misses some.fix(expand): close the gaps the review of #39 found
PhilflowIO commentedon Nov 18, 2026
One more, from the re-review of #39: ical.js gives a rule up silently.
RecurIterator.nextends a YEARLY rule after 28 years without an instance and a MONTHLY one after 336 months, then returns null as if the rule had ended. A fifth Sunday of February can be 40 years away:FREQ=YEARLY;BYMONTH=2;BYDAY=5SUfrom 2058 stops after 2088 and never yields 2128-02-29. The setup (init) has no such cut: it searches to UNTIL or the year 20000.#39 detects the give-up (null although COUNT is not reached and UNTIL not passed) and reports
complete: false, stoppedBy: 'library'; a write check on such a series fails closed. The occurrences after the cut stay unknown until ical.js is fixed or replaced for these rules.fix(expand): say when ical.js gives a rule up in the range
PhilflowIO commentedon Nov 18, 2026
One more, from the final review of #39: COUNT is counted as ical.js counts it, not as RFC 5545 does, when DTSTART is off the rule. RFC 5545 (3.8.5.3) counts DTSTART as the first instance even where the rule would not produce it. ical.js counts only the instances the rule yields, so the series gets one occurrence more. Example:
DTSTART:20580120T130000,RRULE:FREQ=YEARLY;BYMONTH=2;BYDAY=5SU;COUNT=3. RFC: 2058-01-20 plus two fifth Sundays of February. ical.js: 2058-01-20 plus three. tsdav-utils walks COUNT rules from DTSTART in full, with or withoutfrom, so both calls agree, but both follow ical.js here.fix(errors): give the library stop its own refusal code
PhilflowIO commentedon Nov 18, 2026
Three more ical.js 2.2.1 defects, found while fixing #42. All three give the same result with
fromand without it (so no contract break), but the result is not RFC 5545. Checked against a brute-force RFC 5545 expansion (test/rfcOracle.tsin the #42 PR).increment_monthsteps through the BYMONTH list and never reads INTERVAL there.FREQ=MONTHLY;INTERVAL=2;BYMONTH=1,2,3,4;BYMONTHDAY=1from 2026-01-01 yields Jan, Feb, Mar, Apr. RFC 5545: Jan and Mar (every second month, limited to those listed).init, MONTHLY BYDAY branch) computes the weekday in DTSTART's month and yields it untested.FREQ=MONTHLY;BYMONTH=6;BYDAY=1MOfrom 2018-12-01 yields 2018-12-03, a December. The BYMONTHDAY branch had the same leak; the expandOccurrences with from shifts MONTHLY BYMONTHDAY=31,-31 grid #42 fix sets that one up in a listed month, the BYDAY branch is unchanged.expand_year_daysbuilds a date from each listed day without checking that the month has it:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30yields 2 March every year (RFC 5545: never). Without BYMONTH it reads BYMONTHDAY in DTSTART's month only (RFC 5545: every month), soFREQ=YEARLY;BYMONTHDAY=-31from a November yields nothing and ical.js gives the rule up (reportedstoppedBy: 'library'since expandOccurrences with from shifts MONTHLY BYMONTHDAY=31,-31 grid #42's PR, which is the honest verdict there).Scale, from the #42 sweep (box, 2 seeds × 1,500 rules, date-only, compared with RFC 5545): MONTHLY with BYMONTH and INTERVAL > 1 differs in 260 of 305 rules; YEARLY with a month-end BYMONTHDAY (29, 30, 31, -29, -30, -31) in 389 of 570.
PhilflowIO commentedon Nov 18, 2026
Update after the review of #43.
Now handled in #43. Each MONTHLY candidate is checked against RFC 5545 and dropped if it is no instance. COUNT counts only the instances that remain:
BYDAY=5MO;BYSETPOS=2from 1993-05-08 gave 1993-05-31).next_monthtested a new month's 1st only against position 1, soBYDAY=SA;BYSETPOS=-5never gave 2020-08-01. That 1st is now kept.Still open: ical.js here yields no superset of the instances, so dropping candidates cannot fix these:
_byDayAndMonthDaysteps month by month whatever INTERVAL says.FREQ=MONTHLY;INTERVAL=2;BYMONTHDAY=-1,30,29;BYDAY=FR,WEfrom 2012-12-26 yields January, March, May and so on, never the grid's August 2013 (30 August is a Friday).FREQ=MONTHLY;BYDAY=MO;BYHOUR=9,10;BYSETPOS=2from 2026-02-01T09:00 gives 2 Feb (the setup) and 9 Feb, each at 9 and 10, and 1 March at 10:00, a Sunday. RFC 5545 gives the first Monday at 10:00 each month.FREQ=MONTHLY;BYMONTH=6,9;BYDAY=1SA,5TU;BYSETPOS=1from 2022-06-08 misses 2022-09-03.fix(expand): no end proof with BYSETPOS on unchecked candidates
PhilflowIO commentedon Nov 18, 2026
Update after the re-review of #43: what remains.
#43 now checks every MONTHLY and YEARLY candidate against RFC 5545 and drops non-instances; COUNT counts the kept instances. It also compares each period ical.js passes with RFC 5545's instances in it. If ical.js skipped one, the result is
complete: false, stoppedBy: 'library', and a COUNT result stops at the first skipped instance. So for these frequencies ical.js' defects no longer give a wrong result reported as complete; they give a result that says it is incomplete. The YEARLY sweep against the review's oracle (2,000 rules, 6,000fromcalls) finds no complete result that differs.Still open here, because ical.js cannot give the instances (now reported
'library', no longer wrong-but-complete):YEARLY;BYMONTHDAY=15)._byDayAndMonthDaysteps month by month whatever INTERVAL says.Not checked at all: BYWEEKNO, an ordinal weekday under BYMONTHDAY or BYYEARDAY (RFC 5545 leaves the scope open), and COUNT read as ical.js reads it (DTSTART aside, comment above). A fix of the missing instances means computing these rules without ical.js; the period model in
src/recur.ts(periodModel) already gives their sets.PhilflowIO commentedon Nov 18, 2026
Two more, found in the review of PhilflowIO/dav-mcp#174 against an independent RFC 5545 expansion (python-dateutil). Both are returned as complete with no note, on 0.7.0 and 0.8.1 alike:
DTSTART;VALUE=DATE:20250101,RRULE:FREQ=YEARLY;BYWEEKNO=40,2;BYDAY=MO, window 2027-01-05..2027-02-14: every Monday from Jan 11 instead of only Jan 11 (week 2). Correct when DTSTART falls on a matching Monday.DTSTART:20190102T100000Z,RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=SU,WE;BYSETPOS=-1: includes the Wednesdays (2026-01-21, 02-04, 02-18); RFC 5545 gives only the Sundays (BYSETPOS ignored on WEEKLY).Like the MONTHLY/YEARLY candidate check in 0.8.1, these need either an RFC check of the candidates for YEARLY+BYWEEKNO and WEEKLY+BYSETPOS, or a
'library'report, never a silent complete.