Repository navigation
Conversation
|
Related to #91, which fixes the same class of bug on the write path. This one is the read path: on expansion a whole-day occurrence was reported a day early for the same reason, because No overlapping files, so the two should apply independently. |
|
Pushed a follow-up after a closer review of my own diff:
Also dropped two unreachable branches in the EXDATE handling whose comment claimed the opposite. |
|
One more pass, this time on the shape of the change rather than its correctness. Four things came out of it. Every occurrence now carries a handle. Expansion turned one series into many rows, each looking like a single meeting, while the only identifier on them was the series uid — so acting on one through The master/override correlation moved into the module as
Performance. The iterator was always seeded at the series DTSTART, so a daily series from 1990 cost roughly 13,000 steps to yield seven dates, measured at 185ms per event. Whole periods are now skipped for daily and weekly rules, which preserves the phase BYDAY evaluates; COUNT rules are left alone because there the position from the start decides when the series ends. Verified by comparing a jumped walk against a full one. Also removed on the way through: a hand-written RRULE serializer that Two limits I could not fix, now stated in the module header rather than left implicit: Verified against mailbox.org for a summer and a winter week after the change. |
|
Ran the review again over the rewritten branch, which turned up three more things.
Also noted in the source that seeding the iterator somewhere other than the real DTSTART is not something ical.js documents as supported. It holds because the jump is an exact multiple of the period and the algorithm only looks at the phase, but an ical.js upgrade is a reason to re-verify it. The core recurrence arithmetic came through this pass clean: |
38def01 to
79489b3
Compare
Events that began before the query window but still overlap it must be listed. Guards against regressions like the one in dominik1001#94, where only events starting inside the window are returned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dominik1001
left a comment
There was a problem hiding this comment.
Thank you for working on this. Expanding recurring events closes a real gap in list-events, and the coverage in recurrence.test.ts is appreciated. However, the review turned up one regression in existing behaviour and several correctness problems in the expansion itself, so I am requesting changes for now.
Regression
Events that started before the query window but still overlap it are no longer returned. The previous implementation passed through everything the server's time-range filter matched; the new code keeps only events whose start lies inside the window. #114 adds a test for this on main, which is why the test job now fails on this branch: includes events that started before the window but overlap it returns only inside-window. Affected are multi-day events, meetings already running when the window starts, multi-day series occurrences, and all-day events in zones east of UTC (a Berlin all-day event on 21 Aug starts at 2026-08-20T22:00Z and is lost for a window starting at 2026-08-21T00:00Z).
Expansion correctness
The inline comments describe the individual problems: UNTIL compared at the wrong offset, a DATE-valued UNTIL dropping the last day, UTC-anchored series falling back to the system zone, UTC EXDATE and RECURRENCE-ID values never matching, Windows TZIDs, RDATE being ignored, RRULE parts lost in ts-caldav's RecurrenceRule, and all-day occurrences on DST days. The first four were reproduced by running recurrence.ts with TZ=Europe/Berlin; the remainder come from reading the code against ts-caldav and ical.js 2.2.1.
Design
Most of these share one root cause. recurrence.ts rebuilds rules, time zones and exception keys from ts-caldav's partial Event model, because ts-caldav discards the raw iCalendar data. ical.js already implements this: ICAL.Event with its iterator (RecurExpansion) handles the full RRULE, RDATE, EXDATE, RECURRENCE-ID and VTIMEZONE. On one hand, each case could be patched here; on the other hand, every further RFC 5545 edge case would then need another special case. I would prefer obtaining the raw VCALENDAR from ts-caldav (or upstreaming a raw/expand helper there) and letting ical.js do the expansion.
Suggested next steps
Fixing the overlap regression first would get CI green again. After that, it would be good to agree on the design question before addressing the remaining points, since several of them disappear if expansion moves to ical.js.
| const recur = rule ? toRecur(rule) : undefined; | ||
|
|
||
| if (!recur || !rule) { | ||
| const inWindow = event.start >= windowStart && event.start < windowEnd; |
There was a problem hiding this comment.
A non-recurring event is only kept when its start lies inside the window, so events that overlap the window are dropped. For example, an event from 2026-08-20T09:00Z to 2026-08-22T09:00Z, queried for 2026-08-21T00:00Z–2026-08-22T00:00Z, returns nothing; before this PR it was listed. The usual overlap condition would be event.start < windowEnd && event.end > windowStart. This is the case covered by the test from #114.
| if (filtering && (skip.has(key) || replaced.has(key))) continue; | ||
|
|
||
| const start = instantOf(next, timeZone); | ||
| if (start >= windowStart && start < windowEnd) found.push({ start, key }); |
There was a problem hiding this comment.
Same overlap issue for series occurrences: an occurrence that starts before windowStart but is still running is skipped. This needs the occurrence's end (start plus the series duration) to be compared against windowStart, and the lower walking bound has to reach back at least one duration for such occurrences to be visited.
| const rule = event.recurrenceRule; | ||
| const recur = rule ? toRecur(rule) : undefined; | ||
|
|
||
| if (!recur || !rule) { |
There was a problem hiding this comment.
RDATE is not considered here. An event whose DTSTART lies before the window but has an RDATE inside it (e.g. DTSTART 2026-01-05 plus RDATE:20260821T100000Z, queried for the week of 21 Aug) is returned by the server because the RDATE instance overlaps. It is not treated as a series, its DTSTART is outside the window, and it disappears from the result. Before this PR it was listed.
| freq: rule.freq, | ||
| ...(rule.interval ? { interval: rule.interval } : {}), | ||
| ...(rule.count ? { count: rule.count } : {}), | ||
| ...(rule.until ? { until: ICAL.Time.fromJSDate(rule.until, true) } : {}), |
There was a problem hiding this comment.
Two problems with UNTIL here.
First, UNTIL becomes a UTC ICAL.Time, but the iterator walks floating wall-clock times, which ical.js compares with a zero offset. UNTIL is therefore shifted by the zone's UTC offset. A weekly series with DTSTART;TZID=Europe/Berlin:...T143000 and UNTIL=20260821T123000Z (the last occurrence, the form Outlook, Google and Apple write) yields 08-07 and 08-14 only; 08-21 is missing. In zones west of UTC, occurrences after UNTIL appear instead.
Second, for an all-day series with a DATE-valued UNTIL, ts-caldav turns the date into local midnight, and fromJSDate(..., true) makes that the previous day in UTC. A daily all-day series from 2026-08-17 with UNTIL=20260819 yields 17 and 18 Aug in Berlin; 19 Aug is missing.
| * one falls back instead of taking the whole query down. | ||
| */ | ||
| function zoneOf(event: Event): string { | ||
| if (!event.startTzid) return systemZone(); |
There was a problem hiding this comment.
A DTSTART in UTC (the Z form, no TZID) falls back to the system zone here. The series is then expanded on local wall-clock time, so it drifts across DST: a weekly series with DTSTART:20261016T123000Z yields 13:30Z instead of 12:30Z after 25 Oct when the process runs in Berlin. Additionally, UTC EXDATE and RECURRENCE-ID keys no longer match the occurrence keys, so a cancelled instance is still listed and a moved instance appears twice. A UTC DTSTART should probably be walked in UTC.
| ): string | undefined { | ||
| const m = value | ||
| .trim() | ||
| .match(/^(\d{4})-?(\d{2})-?(\d{2})(?:T(\d{2}):?(\d{2}):?(\d{2}))?/); |
There was a problem hiding this comment.
The key drops the trailing Z, so an EXDATE or RECURRENCE-ID given in UTC is compared as if it were wall-clock time in the series' zone. With DTSTART;TZID=Europe/Berlin:...T143000 and EXDATE:20260821T123000Z (valid per RFC 5545), the key 2026-08-21T12:30:00 never equals 2026-08-21T14:30:00, and the excluded date is shown. Server-expanded instances are affected as well, since RFC 4791 returns RECURRENCE-ID in UTC. UTC values would need to be converted into the series' zone before building the key.
| formatterFor(event.startTzid); | ||
| return event.startTzid; | ||
| } catch { | ||
| return systemZone(); |
There was a problem hiding this comment.
When Intl rejects the TZID (for example Exchange's Windows names such as W. Europe Standard Time), expansion falls back to the system zone, while event.start was resolved through the event's VTIMEZONE. With the server running in UTC, such a series is walked at 12:30 instead of 14:30 wall time. EXDATE and RECURRENCE-ID keys then never match, near midnight BYDAY can land on the wrong day, and DST transitions are applied for the wrong zone. Using the VTIMEZONE from the calendar data would avoid this, which ts-caldav does not currently expose.
| function toRecur(rule: RecurrenceRule): ICAL.Recur | undefined { | ||
| if (!rule.freq) return undefined; | ||
| const wkst = Number(rule.wkst); | ||
| return ICAL.Recur.fromData({ |
There was a problem hiding this comment.
The rule is rebuilt from ts-caldav's RecurrenceRule, which keeps no BYSETPOS, BYWEEKNO, BYYEARDAY or BYHOUR. Rules that use them now produce occurrences that do not exist, where the previous code showed only the master. For example, Apple's "first weekday of the month" (FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1) expands to every weekday of every month, roughly 20 phantom meetings per month. For an agent reading list-events, each of these looks like a real conflict. If the raw RRULE cannot be obtained, it would be safer to fall back to returning the master for rules containing parts that cannot be represented.
| uid: event.uid, | ||
| summary: event.summary, | ||
| start, | ||
| end: new Date( |
There was a problem hiding this comment.
The occurrence end is computed as start plus the master's duration in milliseconds. For all-day occurrences on a DST transition day this does not end at midnight: in Berlin, the 25 Oct 2026 occurrence of a daily all-day series (a 25-hour local day) ends at 23:00 local on 25 Oct instead of midnight on 26 Oct, and on the spring-forward day the end is 01:00 the next day. For all-day events, the duration would need to be applied in calendar days rather than milliseconds.
|
Thanks for the review. I agree with the design point: most of the findings come from rebuilding rules, time zones and exception keys out of ts-caldav's partial I looked into doing it your way, and ts-caldav 0.4.5 doesn't give me what I'd need. Server-side expansion doesn't help either. A clean version needs a raw-data accessor or an expand helper in ts-caldav, or a dependency on the private If a small raw-data or expand change in ts-caldav would be acceptable to you, I can start there and rebuild this on ical.js afterwards. The overlap regression you found is independent of all this, and I can split it into its own fix if you want it sooner. |
list-events returned only the master of a recurring series, so a window showed one entry (at the series' original date) instead of its occurrences. Each occurrence now carries its own start and end, `recurring`, and `occurrence`, the wall-clock key in the shape of a RECURRENCE-ID. Servers that honour `expand` are asked to do the work; the rest are expanded locally with ical.js. `uid` still addresses the whole series: update-event and delete-event take nothing finer, so the tool description says they change every instance. Events that started before the window but still overlap it are kept, for single events and for series occurrences alike.
a130fa9 to
040ff92
Compare
…pand
Asking the server to expand made list-events fail on Radicale for a
recurring whole-day event: it answers with an instance carrying
`RECURRENCE-ID:20261117` without VALUE=DATE, which ts-caldav cannot parse
("invalid date-time value"), so the whole call errored. Servers that
ignore `expand` (mailbox.org) never hit this. The master is now always
expanded locally, which is the path the tests cover.
list-eventsanswers a query for next week with theDTSTARTof a series that began two years ago, and the occurrences that actually fall inside the window are missing.getEventscan ask the server to expand a series (RFC 4791<C:expand>), but a server may ignore it, and Open-Xchange does: it returns the master with theRRULEintact. I verified that the<C:expand>element has no effect there.This expands client side with the RRULE engine from
ical.js, already a transitive dependency, now declared directly. Expansion runs on the wall clock of the event's own zone, so a weekly 14:00 appointment stays at 14:00 across a DST change instead of drifting an hour, and a whole-day event keeps its date rather than moving a day east of Greenwich.EXDATEis honoured as far as ts-caldav preserves it (it keeps only the first value of each property).Behaviour change: a series now contributes one entry per occurrence, so several entries can share a
uid. Each entry carries arecurringflag. Marked as a breaking change in the commit footer.Nine unit tests added, including DST and whole-day cases. Verified against mailbox.org: the week that previously reported three 2024 dates now reports the seven actual appointments.