@moltenship/calendar 1.0.0-rc.2 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +24 -4
  2. package/dist/index.d.mts +2 -2
  3. package/docs/accessibility.md +304 -0
  4. package/docs/agents/changes.md +449 -0
  5. package/docs/agents/coding-agents.md +117 -0
  6. package/docs/agents/connect.md +435 -0
  7. package/docs/agents/deleting.md +296 -0
  8. package/docs/agents/reference.md +512 -0
  9. package/docs/agents/server.md +317 -0
  10. package/docs/agents/webmcp.md +153 -0
  11. package/docs/agents.md +353 -0
  12. package/docs/annotations.md +196 -0
  13. package/docs/api/changes.md +248 -0
  14. package/docs/api/dnd-kit.md +267 -0
  15. package/docs/api/events.md +152 -0
  16. package/docs/api/ics.md +524 -0
  17. package/docs/api/primitives.md +168 -0
  18. package/docs/api/react.md +236 -0
  19. package/docs/api/recurrence.md +586 -0
  20. package/docs/api/solid.md +460 -0
  21. package/docs/api/store.md +92 -0
  22. package/docs/api/temporal.md +172 -0
  23. package/docs/api.md +57 -0
  24. package/docs/availability.md +573 -0
  25. package/docs/comparison.md +279 -0
  26. package/docs/concepts/anatomy.md +73 -0
  27. package/docs/concepts/events.md +164 -0
  28. package/docs/concepts/how-it-works.md +95 -0
  29. package/docs/concepts/recurrence.md +127 -0
  30. package/docs/concepts/state.md +244 -0
  31. package/docs/concepts/time.md +170 -0
  32. package/docs/guides/dnd-kit.md +333 -0
  33. package/docs/guides/google-calendar-sync.md +1246 -0
  34. package/docs/guides/google-calendar.md +367 -0
  35. package/docs/guides/ics.md +486 -0
  36. package/docs/guides/motion.md +414 -0
  37. package/docs/guides/nextjs-app-router.md +630 -0
  38. package/docs/guides/nextjs.md +149 -0
  39. package/docs/guides/performance.md +103 -0
  40. package/docs/guides/recurring-events.md +583 -0
  41. package/docs/guides/tanstack-query.md +485 -0
  42. package/docs/index.md +118 -0
  43. package/docs/installation.md +194 -0
  44. package/docs/interactions.md +408 -0
  45. package/docs/llms.txt +86 -0
  46. package/docs/migrating-to-2.md +322 -0
  47. package/docs/quick-start.md +159 -0
  48. package/docs/stylex.md +265 -0
  49. package/docs/testing.md +581 -0
  50. package/docs/theme-builder.md +81 -0
  51. package/docs/theming.md +169 -0
  52. package/docs/undo-redo.md +339 -0
  53. package/docs/views/agenda.md +221 -0
  54. package/docs/views/custom-views.md +192 -0
  55. package/docs/views/month.md +109 -0
  56. package/docs/views/resource-columns.md +261 -0
  57. package/docs/views/resource-timeline.md +225 -0
  58. package/docs/views/scrolling.md +192 -0
  59. package/docs/views/week-and-day.md +257 -0
  60. package/docs/views/year.md +138 -0
  61. package/docs/views.md +69 -0
  62. package/package.json +41 -14
  63. package/skills/moltenship-time/SKILL.md +75 -0
  64. package/skills/moltenship-time/references/agent-ready.md +272 -0
  65. package/skills/moltenship-time/references/changes.md +188 -0
  66. package/skills/moltenship-time/references/compose.md +168 -0
  67. package/skills/moltenship-time/references/mistakes.md +98 -0
  68. package/skills/moltenship-time/references/solid.md +202 -0
  69. package/skills/moltenship-time/references/state.md +129 -0
  70. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,586 @@
1
+ # Recurrence
2
+
3
+ Expand recurring series for the dates on screen, and edit one occurrence, the following ones or all of them, with @moltenship/calendar-recurrence.
4
+
5
+ Source: https://time.molten.sh/docs/api/recurrence
6
+
7
+ `@moltenship/calendar-recurrence` turns your recurring events into the occurrences the calendar
8
+ shows. A series is stored the way iCalendar, Google Calendar and Outlook store it: one master event
9
+ with a rule, plus events that replace single occurrences. The package expands masters for a range
10
+ of dates, and turns a change to one occurrence into what to save for "this event", "this and
11
+ following events" or "all events".
12
+
13
+ It's a separate package. `@moltenship/calendar` doesn't re-export it, and the calendar doesn't need
14
+ it: occurrences reach the calendar as ordinary events, through an adapter. It depends on
15
+ `@moltenship/calendar-core`, `@moltenship/calendar-temporal` and `@moltenship/ics`, and not on
16
+ React.
17
+
18
+ [Recurring events](../concepts/recurrence.md) explains the model, and
19
+ [Show and edit recurring events](../guides/recurring-events.md) wires it into a calendar.
20
+
21
+ ## Install
22
+
23
+ Like the calendar, `@moltenship/calendar-recurrence` is on npm as a release candidate for 1.0.0.
24
+
25
+ **pnpm**
26
+
27
+ ```bash
28
+ pnpm add @moltenship/calendar-recurrence
29
+ ```
30
+
31
+ **npm**
32
+
33
+ ```bash
34
+ npm install @moltenship/calendar-recurrence
35
+ ```
36
+
37
+ **yarn**
38
+
39
+ ```bash
40
+ yarn add @moltenship/calendar-recurrence
41
+ ```
42
+
43
+ **bun**
44
+
45
+ ```bash
46
+ bun add @moltenship/calendar-recurrence
47
+ ```
48
+
49
+ It needs the same setup as the calendar: a runtime with `Temporal`, or a polyfill loaded first,
50
+ and TypeScript's `ESNext` library. See [Installation](../installation.md#temporal).
51
+
52
+ ## Series
53
+
54
+ A series is a master event, which sits at the series' first occurrence, and any number of override
55
+ events. The package reads both through a [`RecurrenceAdapter`](#adapters). Events with neither are
56
+ one-off events, and pass through.
57
+
58
+ Every date of a series has the kind of its first occurrence. That's a `RecurrenceDate`:
59
+
60
+ | The series is | Its dates are | Its occurrence IDs end in |
61
+ | ------------- | ------------------------ | ------------------------- |
62
+ | Timed | `Temporal.Instant` | `2026-10-28T08:00:00Z` |
63
+ | All-day | `Temporal.PlainDate` | `2026-10-28` |
64
+ | Floating | `Temporal.PlainDateTime` | `2026-10-28T09:00:00` |
65
+
66
+ A date of another kind is converted with [`coerceRecurrenceDate`](#dates-of-another-kind), or
67
+ dropped with an issue when it can't be.
68
+
69
+ ### EventRecurrence
70
+
71
+ An `EventRecurrence` is what makes an event a series' master: its RRULE, EXDATE, RDATE and
72
+ DURATION.
73
+
74
+ | Name | Type | Description |
75
+ | ----------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
76
+ | `rule` | `RecurrenceRule` | RRULE. A series without one has only its first occurrence and its `recurrenceDates`. |
77
+ | `exceptionDates` | `readonly RecurrenceDate[]` | EXDATE: original starts of occurrences that don't happen, the first one included. A `PlainDate` on a timed or floating series excludes every occurrence that starts that day. Excluded occurrences still count toward COUNT. |
78
+ | `recurrenceDates` | `readonly (RecurrenceDate \| RecurrencePeriod)[]` | RDATE: extra occurrences. A date starts one that lasts as long as the first occurrence. A `RecurrencePeriod`, with a `start` and an `end`, keeps its own length. |
79
+ | `duration` | `Temporal.Duration` | DURATION, such as `P1D`, which keeps each occurrence's wall-clock length across DST. Without it, occurrences last exactly as long as the first. |
80
+ | `wallStart` | `Temporal.PlainDateTime` | A timed series' first start as written, when it fell in a DST gap and so resolved later. Later occurrences repeat at this wall time. Ignored unless it resolves to the first start. ICS gives it as `wallTime`. |
81
+
82
+ A `RecurrencePeriod` is an extra occurrence with its own `start` and `end`, both in the series'
83
+ kind.
84
+
85
+ `RecurrenceRule` is `@moltenship/ics`'s [`IcsRecurrenceRule`](./ics.md#recurrence), with
86
+ `until` as a `RecurrenceDate`: `frequency`, `interval`, `count`, `until`, `byDay`, `byMonth`,
87
+ `byMonthDay`, `bySetPosition`, `weekStart` and the rest. UNTIL is inclusive. With COUNT too, the
88
+ series ends at whichever comes first.
89
+
90
+ ### RecurrenceOverride
91
+
92
+ A `RecurrenceOverride` is what makes an event replace one occurrence of a series, as RECURRENCE-ID
93
+ does.
94
+
95
+ | Name | Type | Default | Description |
96
+ | -------------- | ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
97
+ | `seriesId` | `TEventId` | | Required. The master's ID. |
98
+ | `recurrenceId` | `RecurrenceDate` | | Required. The original start of the occurrence it replaces, in the series' kind. The override keeps it when it moves, and so keeps the occurrence's ID. |
99
+ | `cancelled` | `boolean` | `false` | The occurrence doesn't happen, as Google's cancelled instances and ICS overrides with STATUS:CANCELLED say. It hides the occurrence and doesn't show itself. |
100
+
101
+ An event that is both a master and an override is read as the override, with a
102
+ `conflicting-recurrence` issue.
103
+
104
+ ### RecurringCalendarEvent
105
+
106
+ `RecurringCalendarEvent<TData, TEventId, TResourceId>` is core's
107
+ [`CalendarEvent`](../concepts/events.md#records-in-times-own-shape) with an optional
108
+ `recurrence: EventRecurrence` and `override: RecurrenceOverride`. Use it when your app has no event
109
+ type of its own, with [`createCanonicalRecurrenceAdapter`](#adapters). It's also what
110
+ [`recurringEventsFromIcs`](#ics-bridge) returns and [`applyRecurrenceEdit`](#applyrecurrenceedit)
111
+ changes.
112
+
113
+ ## Adapters
114
+
115
+ A `RecurrenceAdapter` reads recurrence from your events, beside the `EventAdapter` that reads their
116
+ IDs, titles and intervals. A master's `getInterval` is its first occurrence, as DTSTART and DTEND
117
+ are. Timed series repeat on the wall clock of the interval's `sourceTimeZone`.
118
+
119
+ | Name | Type | Description |
120
+ | --------------- | -------------------------------------------- | ---------------------------------------------------------------------------- |
121
+ | `getRecurrence` | `(event) => EventRecurrence \| undefined` | Required. The recurrence of a series' master; undefined for any other event. |
122
+ | `getOverride` | `(event) => RecurrenceOverride \| undefined` | Which occurrence an override replaces; undefined for any other event. |
123
+
124
+ `RecurrenceAdapters<TEvent, TEventId, TResourceId>` holds both: `{ event, recurrence }`. The
125
+ expander and the edit functions take it.
126
+
127
+ - `createCanonicalRecurrenceAdapter<TData, TEventId, TResourceId>()` returns the adapters for
128
+ `RecurringCalendarEvent`: core's `createCanonicalEventAdapter`, and a recurrence adapter that reads
129
+ `recurrence` and `override`.
130
+ - `createOccurrenceAdapter(eventAdapter)` returns the `EventAdapter` you give the calendar, whose
131
+ events are occurrences. IDs and intervals come from the occurrence. Titles, resources, read-only
132
+ and busy state come from the event it shows, through `eventAdapter`. `isBusy` and `isReadOnly`
133
+ exist only when `eventAdapter` has them, so core's defaults still apply.
134
+
135
+ ```ts
136
+ import { createCalendar } from "@moltenship/calendar";
137
+ import {
138
+ createCanonicalRecurrenceAdapter,
139
+ createOccurrenceAdapter,
140
+ type RecurrenceOccurrence,
141
+ type RecurringCalendarEvent,
142
+ } from "@moltenship/calendar-recurrence";
143
+
144
+ type Event = RecurringCalendarEvent<{ color: string }>;
145
+ const adapters = createCanonicalRecurrenceAdapter<{ color: string }>();
146
+
147
+ const Calendar = createCalendar<RecurrenceOccurrence<Event, string>>()({
148
+ eventAdapter: createOccurrenceAdapter(adapters.event),
149
+ });
150
+ ```
151
+
152
+ An occurrence's revision combines the revisions of its event and its series' master with its
153
+ interval. Without `getRevision` on your adapter, an event's revision is its object identity, so
154
+ replace events rather than changing them.
155
+
156
+ ## Expansion
157
+
158
+ `createOccurrenceExpander(adapters, options)` returns an `OccurrenceExpander`.
159
+ `expander.expand(events, range)` returns the occurrences of `events` that overlap `range`:
160
+
161
+ ```ts
162
+ import { createOccurrenceExpander } from "@moltenship/calendar-recurrence";
163
+
164
+ const expander = createOccurrenceExpander(adapters, { defaultTimeZone: "Europe/Berlin" });
165
+
166
+ const { occurrences, issues } = expander.expand(events, {
167
+ range: visibleRange.loadRange,
168
+ timeZone: "Europe/Berlin",
169
+ });
170
+ ```
171
+
172
+ Create one expander and keep it, in `useState` or at module scope. It reuses its work for events
173
+ that are the same objects as last time: each series keeps its last four ranges and eight rule
174
+ windows, and an occurrence that comes out the same keeps its object, so memoized views don't
175
+ render again. Treat events as immutable.
176
+
177
+ `options` is an `OccurrenceExpanderOptions`:
178
+
179
+ | Name | Type | Default | Description |
180
+ | ----------------- | -------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
181
+ | `defaultTimeZone` | `string` | `"UTC"` | Where timed series without `sourceTimeZone` repeat, and the zone instants are read in for all-day and floating series. Weekdays and DST follow it. A zone that isn't one reports `invalid-time-zone` for each date that needs it. |
182
+ | `maxIterations` | `number` | `DEFAULT_MAX_ITERATIONS (100,000)` | Most loop steps one series may take per expansion. A series that runs out reports `iteration-limit`. Must be a positive integer, or `createOccurrenceExpander` throws a `RangeError`. |
183
+
184
+ ### OccurrenceRange
185
+
186
+ `expand` takes the dates as an `OccurrenceRange`:
187
+
188
+ | Name | Type | Description |
189
+ | ---------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
190
+ | `range` | `{ start: Temporal.PlainDate; end: Temporal.PlainDate }` | Required. Half-open. Pass the `loadRange` that `onVisibleRangeChange` reports, not its `range`, so the pages a scrolling view keeps ready have their occurrences. |
191
+ | `timeZone` | `string` | Required. The calendar's time zone. It places the range's dates for timed series; all-day series compare dates and floating ones wall times. |
192
+
193
+ An occurrence overlapping the range is included, even one that starts before it. Overrides and
194
+ one-off events pass through whatever the range, since your app chose to load them.
195
+
196
+ ### OccurrenceExpansion
197
+
198
+ `expand` returns an `OccurrenceExpansion`: `{ occurrences, issues }`. `occurrences` holds a `RecurrenceOccurrence` for each
199
+ occurrence in the range, each override that isn't cancelled, and each one-off event. They come in
200
+ the input order of their events, and each series' in time order. IDs are unique. Each one has:
201
+
202
+ | Name | Type | Description |
203
+ | ------------ | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
204
+ | `id` | `TEventId \| string` | Required. `occurrenceId(seriesId, recurrenceId)` for an occurrence or an override, and the event's own ID for a one-off event. See [Occurrence IDs](#occurrence-ids). |
205
+ | `interval` | `CalendarEventInterval` | Required. Where it is: the generated start and the series' length, or the override's own interval. |
206
+ | `event` | `TEvent` | Required. The event it shows: the override, the series' master, or the one-off event. |
207
+ | `recurrence` | `OccurrenceRecurrence` | Its place in its series. Absent on one-off events. |
208
+
209
+ `OccurrenceRecurrence` has the `seriesId`, the `recurrenceId` (the original start, which names the
210
+ occurrence and stays put when it moves), the `series` master and the `override` that replaces the
211
+ occurrence, when there is one. `series` is absent for an override whose master isn't among the
212
+ events, such as an invitation to one occurrence. It keeps its ID, so it matches once the master
213
+ loads.
214
+
215
+ ### Issues
216
+
217
+ Bad data becomes an issue, with the event and its position in the input, rather than an
218
+ exception. A problem with one date drops only that date; the series stays.
219
+
220
+ | `code` | Meaning |
221
+ | ------------------------ | ------------------------------------------------------------------------------------------------------------------ |
222
+ | `adapter-error` | An adapter function threw. The event is left out, and `message` names the function. |
223
+ | `date-kind-mismatch` | A date that `coerceRecurrenceDate` can't bring into the series' kind, such as a date-only RDATE on a timed series. |
224
+ | `conflicting-recurrence` | An event is both a master and an override. It's read as the override. |
225
+ | `duplicate-event-id` | Two items have the same ID, such as series `42` and `"42"`. The later one is left out. |
226
+ | `duplicate-override` | Two overrides replace the same occurrence. The later one in the input wins. |
227
+ | `invalid-rule` | The rule can't be expanded. The series still shows its first occurrence and its RDATEs. |
228
+ | `invalid-time-zone` | `sourceTimeZone` or `defaultTimeZone` isn't a time zone. Dates that need it are dropped. |
229
+ | `iteration-limit` | A series ran out of `maxIterations` before it finished the range. |
230
+ | `missing-series` | An override's master isn't among the events. It shows on its own, under its occurrence ID. |
231
+ | `unsupported-rule` | A valid RFC 5545 construct the engine doesn't handle, such as a sub-daily FREQ on an all-day series. |
232
+
233
+ Each `RecurrenceIssue` has its `code`, the `event`, its `eventId` when the adapter could read it, its
234
+ `index` in the input, and a `message`.
235
+
236
+ ## Occurrence IDs
237
+
238
+ ```ts
239
+ import { occurrenceId, parseOccurrenceId, recurrenceKey } from "@moltenship/calendar-recurrence";
240
+
241
+ occurrenceId("standup", Temporal.Instant.from("2026-10-28T08:00:00Z"));
242
+ // "standup::2026-10-28T08:00:00Z"
243
+ occurrenceId(42, Temporal.PlainDate.from("2026-10-28")); // "42::2026-10-28"
244
+
245
+ recurrenceKey(Temporal.Instant.from("2026-10-28T09:00:00+01:00")); // "2026-10-28T08:00:00Z"
246
+
247
+ parseOccurrenceId("standup::2026-10-28T08:00:00Z");
248
+ // { seriesId: "standup", recurrenceKey: "2026-10-28T08:00:00Z" }
249
+ parseOccurrenceId("standup"); // undefined
250
+ ```
251
+
252
+ - `occurrenceId(seriesId, recurrenceId)` is `<seriesId>::<recurrenceKey>`: the series and the
253
+ occurrence's original start. It stays the same across views, time zones and reloads, and when
254
+ an override moves the occurrence. Edits to the following occurrences or to all of them change
255
+ starts, and so IDs.
256
+ - `recurrenceKey(recurrenceId)` is the original start in ISO form: instants in UTC, dates and wall
257
+ times in the ISO calendar, without a calendar annotation. The format is stable, since apps store
258
+ IDs.
259
+ - `parseOccurrenceId(id)` splits an ID into the series ID, as a string, and the key, or returns
260
+ `undefined` for an ID that doesn't end in a key. Use it only for IDs you stored; an occurrence's
261
+ `recurrence` has the series ID with its type.
262
+
263
+ ## Rules
264
+
265
+ ### RRULE text
266
+
267
+ `parseRecurrenceRule(text)` reads an RRULE as a RECUR value (`FREQ=WEEKLY;BYDAY=MO`) or a content
268
+ line (`RRULE:FREQ=WEEKLY;BYDAY=MO`), as the Google Calendar API stores it. It never throws:
269
+
270
+ ```ts
271
+ import { formatRecurrenceRule, parseRecurrenceRule } from "@moltenship/calendar-recurrence";
272
+
273
+ parseRecurrenceRule("RRULE:FREQ=WEEKLY;BYDAY=MO,WE;UNTIL=20261231T225959Z");
274
+ // { rule: { frequency: "WEEKLY", byDay: [{ weekday: "MO" }, { weekday: "WE" }],
275
+ // until: Temporal.Instant 2026-12-31T22:59:59Z }, issues: [] }
276
+
277
+ parseRecurrenceRule("INTERVAL=2");
278
+ // { issues: [{ severity: "error", code: "invalid-value",
279
+ // message: "\"INTERVAL=2\" has no FREQ, which a recurrence rule requires" }] }
280
+
281
+ formatRecurrenceRule({ frequency: "MONTHLY", byDay: [{ weekday: "TU", ordinal: 2 }], count: 6 });
282
+ // "FREQ=MONTHLY;COUNT=6;BYDAY=2TU"
283
+ ```
284
+
285
+ - `parseRecurrenceRule` returns a `RecurrenceRuleTextResult`: `rule`, absent when the text holds
286
+ no usable rule, and `issues`. Each `RecurrenceRuleTextIssue` has a `severity`, the `code`
287
+ `@moltenship/ics` reports it under, and a `message`. Errors leave no rule. Warnings keep a
288
+ best-effort one, as when an invalid BYDAY is dropped.
289
+ - UNTIL becomes a `PlainDate` for a DATE, an `Instant` for a UTC or zoned DATE-TIME, and a
290
+ `PlainDateTime` for a floating one.
291
+ - `formatRecurrenceRule(rule)` writes the RECUR value, without `RRULE:`, its parts in RFC 5545's
292
+ order. An `Instant` UNTIL is written in UTC and rounded down to the second. It throws a
293
+ `RangeError` for an UNTIL outside the years 0 to 9999.
294
+ - `recurrenceRuleFromIcs(icsRule)` converts `IcsEvent.recurrenceRule` from `@moltenship/ics`, and
295
+ returns a `RecurrenceRuleTextResult`. An UNTIL whose TZID resolved to no time zone is an error,
296
+ since the series' end would be unknown. `recurrenceRuleToIcs(rule)` converts back.
297
+
298
+ ### The engine
299
+
300
+ `expandRecurrenceRule(rule, first, window)` lists a rule's starts. The expander calls it for each
301
+ series; call it yourself to list starts without events:
302
+
303
+ ```ts
304
+ import { expandRecurrenceRule } from "@moltenship/calendar-recurrence";
305
+
306
+ const start = Temporal.ZonedDateTime.from("2026-10-19T09:00[Europe/Berlin]");
307
+ const { dates, truncated } = expandRecurrenceRule(
308
+ { frequency: "WEEKLY", byDay: [{ weekday: "MO" }] },
309
+ {
310
+ kind: "timed",
311
+ start: start.toInstant(),
312
+ end: start.add({ minutes: 30 }).toInstant(),
313
+ sourceTimeZone: "Europe/Berlin",
314
+ },
315
+ {
316
+ from: Temporal.Instant.from("2026-10-20T00:00Z"),
317
+ before: Temporal.Instant.from("2026-11-10T00:00Z"),
318
+ },
319
+ );
320
+ // dates: 2026-10-26T08:00:00Z, 2026-11-02T08:00:00Z, 2026-11-09T08:00:00Z
321
+ // (09:00 in Berlin each Monday, after the switch to winter time); truncated: false
322
+ ```
323
+
324
+ It covers RFC 5545: every FREQ, every BY part, BYSETPOS, WKST, COUNT and UNTIL. `first` is a
325
+ `RecurrenceRuleStart`: the first occurrence's interval, with an optional `wallStart`. The first
326
+ occurrence is always one and counts toward COUNT. Dates that don't exist, such as 30 February,
327
+ are skipped and don't count. `window` is a `RecurrenceRuleWindow`:
328
+
329
+ | Name | Type | Default | Description |
330
+ | --------------- | ---------------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
331
+ | `from` | `RecurrenceDate` | | Leaves out starts before this. COUNT still counts them; without COUNT, the engine skips ahead instead of stepping through every earlier period. |
332
+ | `before` | `RecurrenceDate` | | Stops before starts at or after this. |
333
+ | `maxIterations` | `number` | `DEFAULT_MAX_ITERATIONS` | Most steps to take. A step is one period the engine visits, whether or not it gives a start; periods skipped to reach from don't count. |
334
+
335
+ It returns a `RecurrenceRuleExpansion`: `dates`, strictly increasing in the kind of the first
336
+ occurrence and the ISO calendar, and `truncated`, which is `true` when `maxIterations` ran out while
337
+ the rule may still have had starts to give. `DEFAULT_MAX_ITERATIONS` is 100,000.
338
+
339
+ A rule that can never match again ends after its first occurrence, without `truncated`, when the
340
+ engine can tell up front: day parts that meet on no date, such as `BYMONTH=2;BYMONTHDAY=30`, and an
341
+ INTERVAL whose steps never reach the BY values of a fixed cycle, such as
342
+ `FREQ=MINUTELY;INTERVAL=2;BYMINUTE=1` from an even minute. The cycles are the second, minute and
343
+ hour of the day, the weekday of a DAILY rule and the month of a MONTHLY one. Other impossible
344
+ rules, such as `FREQ=MONTHLY;BYDAY=MO;BYSETPOS=6`, show only over time: they run to
345
+ `maxIterations` and report `truncated`.
346
+
347
+ For a rule it can't expand, or a `sourceTimeZone` that isn't a time zone, it throws a
348
+ `RecurrenceRuleError`, a `RangeError` whose `code` is a `RecurrenceRuleErrorCode`:
349
+ `invalid-rule`, `invalid-time-zone` or `unsupported-rule`. The expander reports the same code as an
350
+ issue. Window dates of another kind than `first`, and a `maxIterations` that isn't a positive
351
+ integer, throw a plain `RangeError`.
352
+
353
+ ### Dates of another kind
354
+
355
+ Real feeds mix kinds: a UTC UNTIL on an all-day series, a date-only EXDATE on a timed one.
356
+ `coerceRecurrenceDate(date, first, role, options)` brings a date into the kind of the series' first
357
+ occurrence. It's the one place dates convert, and the expander and the ICS bridge use it.
358
+
359
+ | On a series that is | A `PlainDate` | A `PlainDateTime` | An `Instant` |
360
+ | ------------------- | ------------------------------------------------------------------------------------------- | ------------------------------- | ---------------------------------- |
361
+ | Timed | `"exception"`: stays, the whole day. `"until"`: the end of that day. `"start"`: `undefined` | its instant in the series' zone | itself |
362
+ | All-day | itself | its date | its date in `defaultTimeZone` |
363
+ | Floating | `"exception"`: stays. `"until"`: the end of that day. `"start"`: `undefined` | itself | its wall time in `defaultTimeZone` |
364
+
365
+ `role` is a `RecurrenceDateRole`: `"exception"` for EXDATE, `"start"` for RDATE and
366
+ RECURRENCE-ID, `"until"` for UNTIL. Wall times resolve with `compatible`, as RFC 5545 §3.3.5 says.
367
+ `options` is a `CoerceRecurrenceDateOptions` with a `defaultTimeZone`, UTC by default, for timed
368
+ series without `sourceTimeZone` and for instants on the other kinds. `undefined` means the date
369
+ can't stand for its role; report it and drop only that date.
370
+
371
+ ## ICS bridge
372
+
373
+ `recurringEventsFromIcs(events, options)` groups the VEVENTs that `@moltenship/ics` parsed into
374
+ masters, overrides and one-off events, as `RecurringCalendarEvent`s whose `data` is the `IcsEvent`:
375
+
376
+ ```ts
377
+ import {
378
+ createCanonicalRecurrenceAdapter,
379
+ createOccurrenceExpander,
380
+ recurringEventsFromIcs,
381
+ } from "@moltenship/calendar-recurrence";
382
+ import { parseIcs, type IcsEvent } from "@moltenship/ics";
383
+
384
+ const calendar = parseIcs(text).calendars[0]!;
385
+ const { events, issues } = recurringEventsFromIcs(calendar.events, {
386
+ timeZone: calendar.timeZone,
387
+ });
388
+ const expander = createOccurrenceExpander(createCanonicalRecurrenceAdapter<IcsEvent>());
389
+ ```
390
+
391
+ - Masters and one-off events keep their UID as their ID. An override gets the ID of the occurrence
392
+ it replaces, `occurrenceId(uid, recurrenceId)`, with or without its master.
393
+ - A UTC DTSTART repeats in UTC, and a zoned one in its zone. A DTSTART in a DST gap keeps its
394
+ written time as `recurrence.wallStart`. It moves forward by the gap, as RFC 5545 says; a series
395
+ with DTEND in the same zone keeps the length written between them, and a single event its exact
396
+ length, unless the gap leaves it none. DURATION without DTEND becomes `recurrence.duration`.
397
+ - With `X-MICROSOFT-CDO-ALLDAYEVENT:TRUE`, an event written from midnight to a later midnight, or
398
+ from midnight without an end, as older Outlook and Exchange exports write all-day events, is
399
+ all-day on the dates written, even when its TZID resolves to no zone. Its series' midnight
400
+ EXDATE, UNTIL and RECURRENCE-ID values are those dates. UTC ones read in its DTSTART's zone (UTC
401
+ for a UTC one), else in `timeZone`.
402
+ - EXDATE, RDATE, UNTIL and RECURRENCE-ID take the series' kind through `coerceRecurrenceDate`.
403
+ - A cancelled master or one-off event is left out, with the master's overrides. A cancelled
404
+ override comes out with `override.cancelled`, which hides its occurrence.
405
+ - Of events with the same UID, or UID and RECURRENCE-ID, the highest SEQUENCE wins, then the later
406
+ one.
407
+ - RANGE=THISANDFUTURE, as Apple's "this and future" changes write it, applies to the occurrence it
408
+ names and every later one (RFC 5545 §3.8.4.4). The series splits as a "this and following" edit
409
+ splits it: it ends before the occurrence, and a new series, with the override's ID, VEVENT and
410
+ title, starts where the override is, the rest of the rule moved by the same difference. Later
411
+ EXDATEs, RDATEs and overrides move to it, and overrides take the IDs of the occurrences they then
412
+ replace. Later occurrences are keyed by their new starts, so their `recurrenceId`s aren't the
413
+ feed's RECURRENCE-IDs. On the first occurrence the whole series changes instead. A cancelled one
414
+ ends the series there, and later overrides stay. When the rule can't follow, as a BYSETPOS rule
415
+ moved to another day can't, the override replaces only the occurrence it names, with an
416
+ `unsupported-rule` issue.
417
+
418
+ `options` is an `IcsRecurringEventsOptions`:
419
+
420
+ | Name | Type | Default | Description |
421
+ | ----------------- | ----------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
422
+ | `timeZone` | `string` | `the feed's most used TZID, else UTC` | The feed's time zone: `calendar.timeZone` (X-WR-TIMEZONE), or one you choose. UTC times on all-day and floating series, such as an UNTIL, are read in it, so they keep the feed's dates. Floating DTSTARTs stay floating. Without it, the zone most of the events' TZIDs resolve to, as feeds without X-WR-TIMEZONE, such as Exchange's, need. Pass `"UTC"` for the reading before that default. |
423
+ | `minimumDuration` | `Temporal.DurationLike` | `{ minutes: 30 }` | How long a timed or floating event lasts when DTEND or DURATION make it zero-length or negative. Such all-day events last a day. |
424
+
425
+ It returns an `IcsRecurringEvents`: `events`, in input order, and `issues`. Bad data becomes an
426
+ issue; only invalid options throw, as a `RangeError`. Each `IcsRecurrenceIssue` has its `code`, the
427
+ `event`, its `index`, a `message` and the `property` it concerns, such as `EXDATE`:
428
+
429
+ | `code` (`IcsRecurrenceIssueCode`) | Meaning |
430
+ | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
431
+ | `date-kind-mismatch` | EXDATE, RDATE, UNTIL or RECURRENCE-ID has another kind than the series, or an unresolved TZID. It was converted, or dropped. |
432
+ | `duplicate-event` | Another VEVENT has the same UID, or the same UID and RECURRENCE-ID. The higher SEQUENCE wins, then the later one. |
433
+ | `invalid-period` | An RDATE PERIOD that doesn't end after it starts. Only its start is kept. |
434
+ | `unresolved-time-zone` | DTSTART, or the RECURRENCE-ID of an override without its master, has a TZID that resolved to no time zone. The event is skipped. |
435
+ | `unsupported-rule` | RANGE=THISANDFUTURE the series can't take, or whose series or occurrence isn't in the feed. The override replaces only that one. |
436
+
437
+ The expander reports its own issues on top, such as a rule it can't expand.
438
+
439
+ ## Edits
440
+
441
+ When someone moves, resizes or deletes an occurrence, `onEventChange` receives a change whose
442
+ `event` is the occurrence: a `RecurrenceOccurrenceChange<TEvent, TEventId, TResourceId>`. The edit
443
+ functions turn it into what to save.
444
+
445
+ ```ts
446
+ // `ask` comes from the registry's useRecurrenceScopePrompt.
447
+ const scope = isRecurringChange(change)
448
+ ? await ask({ scopes: recurrenceEditScopes(change, adapters, { timeZone }) })
449
+ : "this";
450
+ // Rolls the change back, and is announced as a cancel.
451
+ if (scope === null) throw new DOMException("Cancelled", "AbortError");
452
+
453
+ const edit = resolveRecurrenceEdit(change, scope, adapters, { newSeriesId, occurrences, timeZone });
454
+ if (edit.type === "rejected") throw new Error(edit.message);
455
+ setEvents(
456
+ (events) =>
457
+ edit.type === "series"
458
+ ? applyRecurrenceEdit(events, edit, { createId })
459
+ : saveOneOff(events, edit.change), // a one-off event, unwrapped: save it as without recurrence
460
+ );
461
+ ```
462
+
463
+ - `isRecurringChange(change)` is `true` for a change to an occurrence of a series, which needs a
464
+ scope. It narrows `change` to a `RecurringOccurrenceChange`. A create, or a change to a one-off
465
+ event, needs none.
466
+ - `recurrenceEditScopes(change, adapters, options)` lists the `RecurrenceEditScope`s worth
467
+ offering, in order: `"this"`, `"following"`, `"all"`. It leaves out those
468
+ `resolveRecurrenceEdit` would reject, and `"following"` where it means `"all"`, as on the first
469
+ occurrence. It's empty for a change that isn't recurring. Hand it to the
470
+ [scope dialog](../guides/recurring-events.md#ask-which-events-a-change-applies-to).
471
+ - `resolveRecurrenceEdit(change, scope, adapters, options)` returns a `RecurrenceEdit`. It reads its
472
+ arguments only: it never changes them or calls your code.
473
+
474
+ Both take a `ResolveRecurrenceEditOptions`:
475
+
476
+ | Name | Type | Default | Description |
477
+ | ----------------- | --------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
478
+ | `defaultTimeZone` | `string` | `"UTC"` | Where timed series without `sourceTimeZone` repeat. Pass the expander's `defaultTimeZone`. |
479
+ | `newSeriesId` | `TEventId` | | The ID the series a `"following"` edit starts will have, when you pick IDs yourself. With it, `newSeries.id` is set and `occurrenceIds` maps into the new series; without it, those occurrences are left out of the map. |
480
+ | `occurrences` | `readonly RecurrenceOccurrence[]` | | The occurrences you show, such as the expansion you give the calendar, so `occurrenceIds` maps their IDs too. |
481
+ | `overrides` | `readonly TEvent[]` | | The series' overrides, or all your events: only cancelled overrides of the edited series are read. They then hide occurrences as EXDATEs do, so `"following"` from the first occurrence left to show is `"all"`. Pass them when you keep deleted occurrences as cancelled overrides, as Google's API does. |
482
+ | `maxIterations` | `number` | | Most loop steps a `"following"` edit's search for the previous occurrence may take. |
483
+ | `timeZone` | `string` | | The calendar's time zone, which occurrences are moved and resized on and the editor shows times in. `"all"` and `"following"` replay the change, calendar days and then exact time, on the series' own clock: a drag by a week keeps its time of day, a drag an hour later moves it an hour, and a resize by days stretches it by days, even in a week when the calendar's zone has changed DST and the series' hasn't. Without it, the calendar is taken to show the series' own zone, and the series takes the instants it proposes, which are an hour off then. An override in another zone replays on its own clock. |
484
+
485
+ ### What each scope does
486
+
487
+ - **`"this"`.** A move, resize or update creates the occurrence's override, or updates it. Its
488
+ `recurrenceId` stays, so the occurrence keeps its ID. A delete adds the original start to the
489
+ master's `exceptionDates` and deletes an existing override. An override whose master isn't
490
+ loaded is marked `cancelled` instead. Google's API records a deleted instance as a cancelled one;
491
+ this package reads those, but writes EXDATE, which every iCalendar store understands.
492
+ - **`"following"`.** The master ends before the occurrence: UNTIL becomes the previous
493
+ occurrence's start, or COUNT the number of occurrences before it. A new series starts where the
494
+ change puts the occurrence, with the rest of the rule moved as `"all"` moves it, and later
495
+ EXDATEs, RDATEs and overrides move to it. A delete only ends the series. Google Calendar and
496
+ Outlook on the web split a series the same way. When nothing before the occurrence is left to
497
+ show, it's `"all"`: EXDATEs count for that, and cancelled overrides when you pass `overrides`.
498
+ - **`"all"`.** The change from where the occurrence showed to where it goes, measured on the
499
+ series' wall clock, applies to every occurrence. The rule moves with it, such as BYDAY when the
500
+ day changes, and so do EXDATEs, RDATEs, UNTIL and every override's `recurrenceId`, so deleted
501
+ occurrences stay deleted and moved ones don't appear twice. Overrides keep their own placements.
502
+ A move keeps the series' length; a resize changes it. A delete removes the master and its
503
+ overrides. An occurrence dropped on the later of two equal wall times, as DST's end repeats an
504
+ hour, gets an override there, since a rule can only say the earlier one, where the rest of the
505
+ series goes.
506
+
507
+ A timed occurrence dropped on a day, or an all-day one dropped on a time, works in every scope.
508
+ `"following"` and `"all"` change the series' kind and convert its dates; a rule with several times
509
+ a day can't become all-day.
510
+
511
+ ### RecurrenceEdit
512
+
513
+ A `RecurrenceEdit` is one of three types:
514
+
515
+ - `{ type: "event", change }`, a `RecurrenceEventEdit`: a create, or a change to a one-off event,
516
+ with the event unwrapped. Apply `change` as you would without recurrence.
517
+ - `{ type: "series", … }`, a `RecurrenceSeriesEdit`, below.
518
+ - `{ type: "rejected", reason, message }`, a `RecurrenceEditRejection`: the scope can't apply.
519
+
520
+ A `RecurrenceSeriesEdit` describes the writes as plain data. Only placement and recurrence are
521
+ described; copy anything else an `"update"` changed, such as the title, yourself.
522
+
523
+ | Name | Type | Description |
524
+ | ---------------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
525
+ | `scope` | `RecurrenceEditScope` | Required. The scope applied. `"following"` on the first occurrence is `"all"`. |
526
+ | `cause` | `"move" \| "resize-start" \| "resize-end" \| "update" \| "delete"` | Required. The change's cause. |
527
+ | `seriesId` | `TEventId` | Required. The master's ID. |
528
+ | `recurrenceId` | `RecurrenceDate` | Required. The edited occurrence's original start. |
529
+ | `series` | `RecurrenceSeriesWrite` | Required. The master: `keep`, `update` with its new `placement` (its first occurrence) and whole `recurrence`, or `delete`. |
530
+ | `newSeries` | `RecurrenceNewSeries` | The series a `"following"` edit starts: copy `from`, the old master, except its ID, placement and recurrence; give it `placement`, `recurrence`, and `id` when you passed `newSeriesId`. |
531
+ | `override` | `RecurrenceOverrideWrite` | The edited occurrence's override: `create` one from the master at `placement`, `update` the existing one (its placement, `recurrenceId`, `cancelled`, and its series when `series` is `"new"`), or `delete` it. |
532
+ | `otherOverrides` | `RecurrenceOverridesRule` | Required. What happens to the series' other overrides, as a rule, since you may not have them all loaded. Apply `recurrenceOverrideEdit` to each one you store. |
533
+ | `occurrenceIds` | `ReadonlyMap<EventId, string>` | Required. Old occurrence IDs to new ones, for your selection: the edited occurrence's and those in `options.occurrences` whose IDs change. Empty for `"this"`. |
534
+
535
+ `RecurrenceSeriesWrite`, `RecurrenceNewSeries` and `RecurrenceOverrideWrite` are the types of
536
+ `series`, `newSeries` and `override`. A placement is a `CalendarEventPlacement`: an interval and its
537
+ `resourceIds`.
538
+
539
+ ### recurrenceOverrideEdit
540
+
541
+ `recurrenceOverrideEdit(edit, recurrenceId)` says what an edit does to one stored override of
542
+ `edit.seriesId`, by its `recurrenceId`. It returns a `RecurrenceOverrideRekey`:
543
+
544
+ - `{ action: "keep" }`, as for the edited occurrence's own override, which `edit.override`
545
+ covers;
546
+ - `{ action: "delete" }`;
547
+ - `{ action: "update", recurrenceId, series }`: its new original start, and `"new"` when it moves
548
+ to the series a `"following"` edit starts. Its own placement stays.
549
+
550
+ `otherOverrides` is a `RecurrenceOverridesRule`: an `action` (`"keep"`, `"rekey"` or `"delete"`),
551
+ `after`, the original start after which it applies, `series`, and `shift`, a `RecurrenceKeyShift`
552
+ that says how original starts move. Read them through `recurrenceOverrideEdit`; the fields of
553
+ `RecurrenceKeyShift` and of its `RecurrenceOrdinalShift`, which moves ordinal weekdays such as the
554
+ 2nd Tuesday within their month or year, may change.
555
+
556
+ ### Rejections
557
+
558
+ `RecurrenceEditRejection.reason` is a `RecurrenceEditRejectionReason`:
559
+
560
+ | `reason` | Meaning |
561
+ | -------------------- | -------------------------------------------------------------------------------------------------------- |
562
+ | `date-kind-mismatch` | The change's dates don't fit the series' kind. |
563
+ | `extra-occurrence` | `"following"` from an occurrence only an RDATE adds, which no rule can continue from. |
564
+ | `invalid-rule` | The engine can't expand the rule, or the one the edit would write. |
565
+ | `invalid-time-zone` | The series' or the placement's zone isn't one Temporal knows. |
566
+ | `iteration-limit` | The search for the previous occurrence ran past `maxIterations`. |
567
+ | `missing-series` | `"following"` or `"all"` on an override whose master isn't loaded. |
568
+ | `rule-cannot-move` | The rule can't follow the change, such as a BYSETPOS rule moved to another day, or the 28th to the 29th. |
569
+ | `unknown-occurrence` | The rule doesn't produce the occurrence any more. |
570
+ | `unsupported-rule` | The engine doesn't handle the rule, or the one the edit would write. |
571
+
572
+ `recurrenceEditScopes` leaves out the scopes that would be rejected, so the dialog offers only
573
+ scopes that apply.
574
+
575
+ ### applyRecurrenceEdit
576
+
577
+ `applyRecurrenceEdit(events, edit, { createId })` applies a series edit to an array of
578
+ `RecurringCalendarEvent`s and returns a new array. It updates or deletes the master, adds the
579
+ series a `"following"` edit starts, writes the edited occurrence's override, and applies
580
+ `recurrenceOverrideEdit` to every other override of the series. Events it doesn't touch stay the
581
+ same objects.
582
+
583
+ `createId(event)`, the one field of `ApplyRecurrenceEditOptions`, returns the ID of an event the
584
+ edit creates: an override, or the new series when `newSeries.id` isn't set. It gets the event
585
+ without its ID. Apps with their own event type or store write the same steps themselves; see
586
+ [Save the edit](../guides/recurring-events.md#save-the-edit).