@moltenship/calendar 1.0.0-rc.2 → 2.0.0
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.
- package/README.md +27 -6
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/docs/accessibility.md +305 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +116 -0
- package/docs/agents/connect.md +444 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +511 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +355 -0
- package/docs/annotations.md +198 -0
- package/docs/api/changes.md +264 -0
- package/docs/api/components.md +245 -0
- package/docs/api/dnd-kit.md +265 -0
- package/docs/api/events.md +153 -0
- package/docs/api/primitives.md +218 -0
- package/docs/api/store.md +92 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +576 -0
- package/docs/comparison.md +278 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +163 -0
- package/docs/concepts/how-it-works.md +112 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +168 -0
- package/docs/customization.md +271 -0
- package/docs/frameworks.md +116 -0
- package/docs/guides/dnd-kit.md +333 -0
- package/docs/guides/google-calendar-sync.md +1246 -0
- package/docs/guides/google-calendar.md +367 -0
- package/docs/guides/motion.md +414 -0
- package/docs/guides/nextjs-app-router.md +630 -0
- package/docs/guides/nextjs.md +149 -0
- package/docs/guides/performance.md +103 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/ics/feed.md +484 -0
- package/docs/ics/import.md +183 -0
- package/docs/ics/reference.md +482 -0
- package/docs/ics.md +142 -0
- package/docs/index.md +149 -0
- package/docs/installation.md +209 -0
- package/docs/interactions.md +441 -0
- package/docs/llms.txt +99 -0
- package/docs/migrating-to-2.md +497 -0
- package/docs/quick-start.md +163 -0
- package/docs/recurrence/calendar.md +598 -0
- package/docs/recurrence/model.md +128 -0
- package/docs/recurrence/reference.md +547 -0
- package/docs/recurrence.md +122 -0
- package/docs/stylex.md +290 -0
- package/docs/temporal/daylight-saving-time.md +172 -0
- package/docs/temporal/month-grid.md +119 -0
- package/docs/temporal/reference.md +167 -0
- package/docs/temporal.md +105 -0
- package/docs/testing.md +600 -0
- package/docs/theme-builder.md +82 -0
- package/docs/theming.md +275 -0
- package/docs/undo-redo.md +347 -0
- package/docs/views/agenda.md +222 -0
- package/docs/views/custom-views.md +195 -0
- package/docs/views/month.md +110 -0
- package/docs/views/resource-columns.md +265 -0
- package/docs/views/resource-timeline.md +226 -0
- package/docs/views/scrolling.md +193 -0
- package/docs/views/week-and-day.md +258 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +42 -14
- package/skills/moltenship-time/SKILL.md +77 -0
- package/skills/moltenship-time/references/agent-ready.md +272 -0
- package/skills/moltenship-time/references/changes.md +188 -0
- package/skills/moltenship-time/references/compose.md +175 -0
- package/skills/moltenship-time/references/mistakes.md +100 -0
- package/skills/moltenship-time/references/solid.md +213 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
Everything @moltenship/ics exports. Calendars and events, dates and time zones, issues and strict mode, extensions, and the lower layers.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/ics/reference
|
|
6
|
+
|
|
7
|
+
Everything on this page is exported from `@moltenship/ics`. The [Overview](../ics.md) has the
|
|
8
|
+
install command and a first example.
|
|
9
|
+
|
|
10
|
+
To show a feed's events in the calendar, follow [Show an ICS feed](./feed.md).
|
|
11
|
+
|
|
12
|
+
## Parse
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { parseIcs } from "@moltenship/ics";
|
|
16
|
+
|
|
17
|
+
const response = await fetch("https://example.com/team.ics");
|
|
18
|
+
const { calendars, issues } = parseIcs(await response.text());
|
|
19
|
+
|
|
20
|
+
for (const event of calendars[0]?.events ?? []) {
|
|
21
|
+
console.log(event.summary, event.start);
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`parseIcs(text, options)` returns two lists:
|
|
26
|
+
|
|
27
|
+
- `calendars`: every VCALENDAR in the text, usually one. Their components keep the order of the
|
|
28
|
+
text.
|
|
29
|
+
- `issues`: every deviation from RFC 5545 the parser found, with its line. See
|
|
30
|
+
[Issues and strict mode](#issues-and-strict-mode).
|
|
31
|
+
|
|
32
|
+
Parsing is lenient. The parser keeps what it can read, skips components it can't type, such as an
|
|
33
|
+
event without `UID` or `DTSTART`, and reports each problem as an issue. Bad data never throws.
|
|
34
|
+
Text without a VCALENDAR, empty text included, gives no calendars and an error.
|
|
35
|
+
|
|
36
|
+
To parse many texts with the same options, create a parser once:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { createIcsParser } from "@moltenship/ics";
|
|
40
|
+
|
|
41
|
+
const parser = createIcsParser({ strict: true });
|
|
42
|
+
const { calendars } = parser.parse(text);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`parseIcs(text, options)` is the same as `createIcsParser(options).parse(text)`.
|
|
46
|
+
|
|
47
|
+
### Calendars
|
|
48
|
+
|
|
49
|
+
Each calendar is an `IcsCalendar`. Optional fields are absent when the file doesn't set them, and
|
|
50
|
+
lists are empty.
|
|
51
|
+
|
|
52
|
+
| Name | Type | Description |
|
|
53
|
+
| ----------------- | ------------------------ | ----------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `events` | `readonly IcsEvent[]` | Required. VEVENTs, in the order of the text. |
|
|
55
|
+
| `todos` | `readonly IcsTodo[]` | Required. VTODOs. |
|
|
56
|
+
| `journals` | `readonly IcsJournal[]` | Required. VJOURNALs. |
|
|
57
|
+
| `freeBusy` | `readonly IcsFreeBusy[]` | Required. VFREEBUSYs. |
|
|
58
|
+
| `timeZones` | `readonly IcsTimeZone[]` | Required. VTIMEZONEs, each with its `tzid` as written and the `timeZone` it resolved to. |
|
|
59
|
+
| `name` | `string` | NAME (RFC 7986), else X-WR-CALNAME. |
|
|
60
|
+
| `description` | `string` | DESCRIPTION (RFC 7986), else X-WR-CALDESC. |
|
|
61
|
+
| `timeZone` | `string` | X-WR-TIMEZONE, resolved to a time zone id. See [Dates and times](#dates-and-times). |
|
|
62
|
+
| `refreshInterval` | `Temporal.Duration` | REFRESH-INTERVAL (RFC 7986), else X-PUBLISHED-TTL. |
|
|
63
|
+
| `method` | `string` | METHOD, such as PUBLISH, REQUEST or CANCEL. |
|
|
64
|
+
| `productId` | `string` | PRODID: the app that wrote the file. |
|
|
65
|
+
| `color` | `string` | COLOR (RFC 7986). |
|
|
66
|
+
| `extensions` | `object` | Required. The `X-` properties you declared. See [Extensions](#extensions-with-standard-schema). |
|
|
67
|
+
| `otherProperties` | `readonly IcsProperty[]` | Required. Properties no field maps, such as other X- properties. |
|
|
68
|
+
|
|
69
|
+
It also has `calendarScale`, `lastModified`, `source`, `uid`, `url`, `version` and
|
|
70
|
+
`otherComponents`.
|
|
71
|
+
|
|
72
|
+
### Events
|
|
73
|
+
|
|
74
|
+
Each event is an `IcsEvent`:
|
|
75
|
+
|
|
76
|
+
| Name | Type | Description |
|
|
77
|
+
| ----------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
78
|
+
| `uid` | `string` | Required. UID. An event without one is reported and skipped. |
|
|
79
|
+
| `start` | `IcsDateValue` | Required. DTSTART: a date or a date-time. See [Dates and times](#dates-and-times). An event without one is reported and skipped. |
|
|
80
|
+
| `end` | `IcsDateValue` | DTEND as written. Use [getEventEnd](#ends-of-events) for the effective end. |
|
|
81
|
+
| `duration` | `Temporal.Duration` | DURATION as written. |
|
|
82
|
+
| `summary` | `string` | SUMMARY, with escapes such as \, and \n decoded. |
|
|
83
|
+
| `description` | `string` | DESCRIPTION. |
|
|
84
|
+
| `location` | `string` | LOCATION. |
|
|
85
|
+
| `status` | `string` | STATUS: CONFIRMED, TENTATIVE or CANCELLED. |
|
|
86
|
+
| `transparency` | `string` | TRANSP: OPAQUE (busy) or TRANSPARENT (free). |
|
|
87
|
+
| `organizer` | `IcsCalendarUser` | ORGANIZER. |
|
|
88
|
+
| `attendees` | `readonly IcsAttendee[]` | Required. ATTENDEE, every occurrence. |
|
|
89
|
+
| `recurrenceRule` | `IcsRecurrenceRule` | RRULE. See [Recurrence](#recurrence). |
|
|
90
|
+
| `exceptionDates` | `readonly IcsDateValue[]` | Required. EXDATE. |
|
|
91
|
+
| `recurrenceDates` | `readonly (IcsDateValue \| IcsPeriod)[]` | Required. RDATE. |
|
|
92
|
+
| `recurrenceId` | `IcsDateValue` | RECURRENCE-ID: the occurrence of a series this event replaces. |
|
|
93
|
+
| `alarms` | `readonly IcsAlarm[]` | Required. VALARMs. |
|
|
94
|
+
| `categories` | `readonly string[]` | Required. CATEGORIES, every value. |
|
|
95
|
+
| `stamp` | `Temporal.Instant` | DTSTAMP. Required by RFC 5545, but often missing from exports. |
|
|
96
|
+
| `extensions` | `object` | Required. The `X-` properties you declared. See [Extensions](#extensions-with-standard-schema). |
|
|
97
|
+
| `otherProperties` | `readonly IcsProperty[]` | Required. Properties no field maps, such as X-MICROSOFT-CDO-BUSYSTATUS. |
|
|
98
|
+
|
|
99
|
+
Events also have `attachments`, `classification`, `color`, `comments`, `conferences`, `contacts`,
|
|
100
|
+
`created`, `geo`, `lastModified`, `priority`, `recurrenceRange`, `relatedTo`, `resources`,
|
|
101
|
+
`sequence`, `url` and `otherComponents`.
|
|
102
|
+
|
|
103
|
+
The organizer and attendees are calendar users. `address` is the value as written, such as
|
|
104
|
+
`mailto:ann@example.com`, `email` comes from the `EMAIL` parameter or the address without
|
|
105
|
+
`mailto:`, and `name` comes from the `CN` parameter. Attendees add `participationStatus`, `role`, `rsvp` and the other `ATTENDEE`
|
|
106
|
+
parameters.
|
|
107
|
+
|
|
108
|
+
To-dos (`IcsTodo`) and journals (`IcsJournal`) share most of these fields. Every type is
|
|
109
|
+
exported, and each field has a doc comment that your editor shows.
|
|
110
|
+
|
|
111
|
+
## Dates and times
|
|
112
|
+
|
|
113
|
+
A `DATE` value is a `Temporal.PlainDate`. A `DATE-TIME` value can mean several things, so it's a
|
|
114
|
+
union, and `kind` says what the file wrote:
|
|
115
|
+
|
|
116
|
+
| `kind` | Written as | Fields |
|
|
117
|
+
| ------------ | --------------------------------------- | --------------------------------------------------------------------- |
|
|
118
|
+
| `date` | `DTSTART;VALUE=DATE:20261016` | `date: Temporal.PlainDate` |
|
|
119
|
+
| `utc` | `DTSTART:20261014T080000Z` | `instant: Temporal.Instant` |
|
|
120
|
+
| `zoned` | `DTSTART;TZID=Europe/Berlin:20261014T…` | `zoned: Temporal.ZonedDateTime`, `wallTime`, `tzid` |
|
|
121
|
+
| `unresolved` | `DTSTART;TZID=Head office:20261014T…` | `wallTime: Temporal.PlainDateTime`, `tzid` |
|
|
122
|
+
| `floating` | `DTSTART:20261014T100000` | `wallTime: Temporal.PlainDateTime`: the same clock time in every zone |
|
|
123
|
+
|
|
124
|
+
`zoned` is a TZID that resolved to a time zone, and `unresolved` one that didn't. See
|
|
125
|
+
[Time zones](#time-zones). Switch on `kind` to get what you need, such as an instant:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import type { IcsDateValue } from "@moltenship/ics";
|
|
129
|
+
|
|
130
|
+
function startInstant(start: IcsDateValue, timeZone: string): Temporal.Instant {
|
|
131
|
+
switch (start.kind) {
|
|
132
|
+
case "utc":
|
|
133
|
+
return start.instant;
|
|
134
|
+
case "zoned":
|
|
135
|
+
return start.zoned.toInstant();
|
|
136
|
+
case "date":
|
|
137
|
+
return start.date.toZonedDateTime(timeZone).toInstant();
|
|
138
|
+
case "floating":
|
|
139
|
+
case "unresolved":
|
|
140
|
+
return start.wallTime.toZonedDateTime(timeZone).toInstant();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The same union holds `DTEND`, `DUE`, `RECURRENCE-ID`, `EXDATE`, `RDATE` and a rule's `UNTIL`.
|
|
146
|
+
|
|
147
|
+
A wall time that falls in a daylight saving gap or fold resolves the way RFC 5545 §3.3.5 says,
|
|
148
|
+
which is Temporal's `compatible` disambiguation: a time in a gap moves forward by the gap's length,
|
|
149
|
+
and a time in a fold takes the earlier of the two. `wallTime` keeps what the file wrote:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// DTSTART;TZID=Europe/Berlin:20260329T023000, in the hour Berlin skips
|
|
153
|
+
const { start } = parseIcs(text).calendars[0]!.events[0]!;
|
|
154
|
+
|
|
155
|
+
if (start.kind === "zoned") {
|
|
156
|
+
start.wallTime.toString(); // "2026-03-29T02:30:00"
|
|
157
|
+
start.zoned.toString(); // "2026-03-29T03:30:00+02:00[Europe/Berlin]"
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Nothing falls back to the host's time zone, so the result is the same on every machine. A floating
|
|
162
|
+
time stays floating. If the calendar has an `X-WR-TIMEZONE`, as Google's feeds do, its resolved id
|
|
163
|
+
is `calendar.timeZone`: the zone the publisher meant for floating times. Apply it yourself if you
|
|
164
|
+
want it.
|
|
165
|
+
|
|
166
|
+
## Time zones
|
|
167
|
+
|
|
168
|
+
Temporal has no custom time zones, so it can't use the definitions inside a file. Instead, the
|
|
169
|
+
parser maps each TZID to a time zone Temporal knows. It tries, in order:
|
|
170
|
+
|
|
171
|
+
1. your `resolveTimeZone(tzid, vtimezone)` option, if it returns an id Temporal knows;
|
|
172
|
+
2. IANA ids, such as `Europe/Berlin`;
|
|
173
|
+
3. vendor paths, such as `/mozilla.org/20050126_1/Europe/Berlin`;
|
|
174
|
+
4. Windows ids and Outlook display names, such as `W. Europe Standard Time` or
|
|
175
|
+
`(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna`, through the Unicode CLDR
|
|
176
|
+
mapping;
|
|
177
|
+
5. the file's VTIMEZONE: its `X-LIC-LOCATION`, or a fixed offset when it has no daylight saving
|
|
178
|
+
time;
|
|
179
|
+
6. offset names, such as `GMT+0100` or `UTC`.
|
|
180
|
+
|
|
181
|
+
A TZID can name a zone that never changes offset while the file's VTIMEZONE has daylight saving
|
|
182
|
+
rules. `TZID=EST` on its own is Temporal's fixed −05:00 zone, but a VTIMEZONE called `EST` with
|
|
183
|
+
summer rules usually means New York. When the VTIMEZONE observes daylight saving time, steps 2–4
|
|
184
|
+
and 6 skip zones that don't, so the wrong fixed zone is never picked.
|
|
185
|
+
|
|
186
|
+
A TZID that matches none of these stays `unresolved`, with an `unknown-time-zone` warning. The
|
|
187
|
+
parser doesn't guess:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
// DTSTART;TZID=Head office:20261014T100000
|
|
191
|
+
const { calendars, issues } = parseIcs(text);
|
|
192
|
+
|
|
193
|
+
calendars[0]!.events[0]!.start;
|
|
194
|
+
// { kind: "unresolved", tzid: "Head office", wallTime: 2026-10-14T10:00:00 }
|
|
195
|
+
issues[0]!.code; // "unknown-time-zone"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
If you know what your feeds mean, say so with `resolveTimeZone`. The parser asks it before its own
|
|
199
|
+
rules:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
const { calendars } = parseIcs(text, {
|
|
203
|
+
resolveTimeZone: (tzid) => (tzid === "Head office" ? "Europe/Lisbon" : undefined),
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The second argument is the file's VTIMEZONE with that TZID, as a raw component, if there is one.
|
|
208
|
+
Return an IANA id or a `±HH:MM` offset, or `undefined` to fall through to the rules above. An id
|
|
209
|
+
Temporal doesn't know falls through too.
|
|
210
|
+
|
|
211
|
+
## Ends of events
|
|
212
|
+
|
|
213
|
+
An event's end can be written as `DTEND`, as `DURATION`, or not at all. `event.end` and
|
|
214
|
+
`event.duration` keep what the file says, and `getEventEnd` works out the end:
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import { getEventEnd } from "@moltenship/ics";
|
|
218
|
+
|
|
219
|
+
const end = getEventEnd(event); // an IcsDateValue of the same kind as event.start
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
- With `DTEND`, it's `DTEND`, converted to the start's kind if it differs. A `DTEND` in another
|
|
223
|
+
zone keeps its instant; one without an instant keeps its wall time.
|
|
224
|
+
- With `DURATION`, it's the start plus the duration. On a zoned start, days are calendar days and
|
|
225
|
+
hours are exact hours, as RFC 5545 §3.3.6 says, so `P1D` across a daylight saving change keeps
|
|
226
|
+
the wall time. On a date start, it adds whole days, and a time part rounds up to a day.
|
|
227
|
+
- With neither, an all-day event ends the next day and a timed event ends when it starts.
|
|
228
|
+
|
|
229
|
+
An event with both `DTEND` and `DURATION` keeps `DTEND`, and the parser drops `DURATION` with a
|
|
230
|
+
`conflicting-properties` warning.
|
|
231
|
+
|
|
232
|
+
## Recurrence
|
|
233
|
+
|
|
234
|
+
A recurring event is one `IcsEvent` with a rule, such as the design review in the playground:
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
// RRULE:FREQ=WEEKLY;BYDAY=WE;COUNT=6
|
|
238
|
+
// EXDATE;TZID=Europe/Berlin:20261028T100000
|
|
239
|
+
event.recurrenceRule;
|
|
240
|
+
// { frequency: "WEEKLY", byDay: [{ weekday: "WE" }], count: 6 }
|
|
241
|
+
event.exceptionDates;
|
|
242
|
+
// [{ kind: "zoned", zoned: 2026-10-28T10:00:00+01:00[Europe/Berlin], … }]
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
- `recurrenceRule` is the `RRULE` as an `IcsRecurrenceRule`, with named parts: `frequency`,
|
|
246
|
+
`interval`, `count`, `until`, `byDay`, `byMonth`, `byMonthDay`, `weekStart` and the rest. Parts
|
|
247
|
+
the rule doesn't state are absent, and defaults such as an `interval` of 1 aren't filled in.
|
|
248
|
+
- `exceptionDates` lists the `EXDATE` values: occurrences that don't happen.
|
|
249
|
+
- `recurrenceDates` lists the `RDATE` values: extra occurrences, as dates, date-times or periods.
|
|
250
|
+
- `recurrenceId` is set on an override: a separate event with the series' `UID` that replaces one
|
|
251
|
+
occurrence, such as a meeting moved to another time. `recurrenceRange` is `"THISANDFUTURE"` when
|
|
252
|
+
the override also applies to the occurrences after it.
|
|
253
|
+
|
|
254
|
+
This package parses rules but doesn't list a series' occurrences.
|
|
255
|
+
[`@moltenship/calendar-recurrence`](../recurrence.md) does: `recurringEventsFromIcs` groups
|
|
256
|
+
parsed events into series masters, overrides and one-off events, and its expander lists the
|
|
257
|
+
occurrences for a range of dates. It applies an override with `RANGE=THISANDFUTURE` to the
|
|
258
|
+
occurrences after it too, by splitting the series.
|
|
259
|
+
|
|
260
|
+
See [Recurring events](./feed.md#recurring-events) in the feed guide.
|
|
261
|
+
|
|
262
|
+
## Issues and strict mode
|
|
263
|
+
|
|
264
|
+
Each issue says what's wrong and where:
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
{
|
|
268
|
+
severity: "warning",
|
|
269
|
+
code: "invalid-value",
|
|
270
|
+
message: "DTSTART: a DATE where DATE-TIME is declared; read as DATE",
|
|
271
|
+
line: 62,
|
|
272
|
+
path: ["calendars", 0, "events", 3, "start"],
|
|
273
|
+
component: "VEVENT",
|
|
274
|
+
property: "DTSTART",
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
- `severity` is `"error"` or `"warning"`. An error drops the value or component it concerns. A
|
|
279
|
+
warning keeps a best-effort value, such as the date above.
|
|
280
|
+
- `line` is the 1-based line in the text, when the issue comes from one. A component skipped for a
|
|
281
|
+
missing property reports its `BEGIN` line; one skipped for an invalid value reports that
|
|
282
|
+
property's line.
|
|
283
|
+
- `path` is where the issue lands in the result. Indexes count the components that were kept, so
|
|
284
|
+
a skipped event's path ends at `events`. It's empty for problems with the text's structure.
|
|
285
|
+
- `component` and `property` name the component and property, when there is one.
|
|
286
|
+
|
|
287
|
+
`code` says what kind of problem it is:
|
|
288
|
+
|
|
289
|
+
| Code | Severity | Meaning |
|
|
290
|
+
| ------------------------ | ---------------- | -------------------------------------------------------------------------------------------------------- |
|
|
291
|
+
| `missing-property` | error | A required property, such as `UID` or `DTSTART`, is missing. The component is skipped. |
|
|
292
|
+
| `invalid-value` | error or warning | A value doesn't parse as its type, or parses only leniently. |
|
|
293
|
+
| `invalid-content-line` | warning | A line isn't `NAME;PARAM=…:value`, or has an invalid parameter. |
|
|
294
|
+
| `invalid-structure` | error or warning | An error when there's no VCALENDAR; a warning for an `END` without its `BEGIN` or a component left open. |
|
|
295
|
+
| `duplicate-property` | warning | A property that may occur once occurs again. The first one wins. |
|
|
296
|
+
| `conflicting-properties` | warning | Properties that exclude each other, such as `DTEND` and `DURATION`. |
|
|
297
|
+
| `unknown-time-zone` | warning | A TZID that resolves to no time zone. The value stays `unresolved`. |
|
|
298
|
+
| `unsupported` | warning | Something the parser recognizes but doesn't interpret, such as `RSCALE`. |
|
|
299
|
+
| `schema` | error | An extension's schema rejected a value. See [Extensions](#extensions-with-standard-schema). |
|
|
300
|
+
|
|
301
|
+
Pass `strict: true` to throw instead when there's an error. The parser throws an `IcsParseError`
|
|
302
|
+
whose `issues` lists the error-severity issues. Warnings never throw.
|
|
303
|
+
|
|
304
|
+
```ts
|
|
305
|
+
import { IcsParseError, parseIcs } from "@moltenship/ics";
|
|
306
|
+
|
|
307
|
+
function readFeed(text: string) {
|
|
308
|
+
try {
|
|
309
|
+
return parseIcs(text, { strict: true }).calendars;
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (error instanceof IcsParseError) {
|
|
312
|
+
console.error(error.message); // "VEVENT has no DTSTART; skipped (and 2 more)"
|
|
313
|
+
console.error(error.issues); // every error-severity issue
|
|
314
|
+
}
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
The error's `message` is the first issue's message, with a count of the others.
|
|
321
|
+
|
|
322
|
+
An exception thrown by a function you pass in, `resolveTimeZone` or an extension schema, comes out
|
|
323
|
+
of `parse` unchanged, strict or not. That's a bug in your code, not a problem with the text.
|
|
324
|
+
|
|
325
|
+
## Extensions with Standard Schema
|
|
326
|
+
|
|
327
|
+
Calendar apps add their own `X-` properties, such as Outlook's busy status. Undeclared, they land
|
|
328
|
+
in `otherProperties` as raw text. Declare the ones you rely on with `icsExtension`, and they're
|
|
329
|
+
decoded, validated and typed in `extensions`:
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
import { createIcsParser, icsExtension } from "@moltenship/ics";
|
|
333
|
+
import { z } from "zod";
|
|
334
|
+
|
|
335
|
+
const extensions = {
|
|
336
|
+
event: {
|
|
337
|
+
busyStatus: icsExtension("X-MICROSOFT-CDO-BUSYSTATUS", {
|
|
338
|
+
schema: z.enum(["FREE", "TENTATIVE", "BUSY", "OOF", "WORKINGELSEWHERE"]),
|
|
339
|
+
}),
|
|
340
|
+
resourceIds: icsExtension("X-RESOURCE-ID", { multiple: true }),
|
|
341
|
+
guests: icsExtension("X-EXAMPLE-GUESTS", { type: "INTEGER" }),
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const parser = createIcsParser({ extensions });
|
|
346
|
+
const { calendars } = parser.parse(text);
|
|
347
|
+
const event = calendars[0]!.events[0]!;
|
|
348
|
+
|
|
349
|
+
event.extensions.busyStatus; // "FREE" | "TENTATIVE" | … | undefined
|
|
350
|
+
event.extensions.resourceIds; // readonly string[]
|
|
351
|
+
event.extensions.guests; // number | undefined
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
`extensions` has a map for each component kind: `calendar`, `event`, `todo` and `journal`. Each
|
|
355
|
+
key is the field name in `extensions`, and `icsExtension(name, options)` takes the property's name
|
|
356
|
+
and these options:
|
|
357
|
+
|
|
358
|
+
| Name | Type | Default | Description |
|
|
359
|
+
| ---------- | ------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
360
|
+
| `type` | `IcsValueType` | `"TEXT"` | The RFC 5545 value type to decode the raw value as, such as INTEGER, DATE-TIME or DURATION, whatever the property's VALUE parameter says. |
|
|
361
|
+
| `multiple` | `boolean` | `false` | Collect every occurrence and every comma-separated value into an array, which is empty when there's none. |
|
|
362
|
+
| `schema` | `StandardSchemaV1` | | Validates or transforms each decoded value: Zod, Valibot, ArkType or any other Standard Schema. Its input type must accept the decoded value. |
|
|
363
|
+
|
|
364
|
+
The types are inferred: a schema's output type if it has one, else the value type's decoded type,
|
|
365
|
+
such as `number` for `INTEGER` or `IcsDateValue` for `DATE-TIME`. Without `multiple`, a property
|
|
366
|
+
that's missing gives `undefined`.
|
|
367
|
+
|
|
368
|
+
A value the schema rejects is dropped with a `schema` issue. That's an error, so strict parsing
|
|
369
|
+
throws and [validation](#as-a-standard-schema) fails. Schemas must validate synchronously: a schema
|
|
370
|
+
that returns a promise, such as one with an async refinement, drops the value with a `schema` error
|
|
371
|
+
too.
|
|
372
|
+
|
|
373
|
+
To name the result's types in your own code, keep the `extensions` object in a constant, as above.
|
|
374
|
+
Every type takes it the same way: `IcsCalendar<typeof extensions>`, `IcsEvent<typeof extensions>`.
|
|
375
|
+
|
|
376
|
+
## As a Standard Schema
|
|
377
|
+
|
|
378
|
+
A parser is itself a [Standard Schema](https://standardschema.dev) that validates ICS text, so it
|
|
379
|
+
plugs into anything that takes one, such as a form library or a router's body validation. It fails
|
|
380
|
+
with the error-severity issues, each with its `message` and `path`, or succeeds with the parse
|
|
381
|
+
result. Warnings don't fail it.
|
|
382
|
+
|
|
383
|
+
```ts
|
|
384
|
+
import { createIcsParser } from "@moltenship/ics";
|
|
385
|
+
|
|
386
|
+
const parser = createIcsParser();
|
|
387
|
+
|
|
388
|
+
async function readUpload(body: unknown) {
|
|
389
|
+
const result = await parser["~standard"].validate(body);
|
|
390
|
+
if (result.issues) {
|
|
391
|
+
return { status: 400, errors: result.issues.map((issue) => issue.message) };
|
|
392
|
+
}
|
|
393
|
+
return { status: 200, calendars: result.value.calendars };
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
A value that isn't a string fails too.
|
|
398
|
+
|
|
399
|
+
## Lower layers
|
|
400
|
+
|
|
401
|
+
`parseIcs` is the top of three layers, and each is exported. When the typed model doesn't cover
|
|
402
|
+
your data, drop down a layer.
|
|
403
|
+
|
|
404
|
+
### Syntax
|
|
405
|
+
|
|
406
|
+
`parseIcsComponents(text)` splits the text into a lossless tree of components and properties, with
|
|
407
|
+
values exactly as written, and reports only syntax issues:
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
import { parseIcsComponents, stringifyIcsComponents } from "@moltenship/ics";
|
|
411
|
+
|
|
412
|
+
const { components, issues } = parseIcsComponents(text);
|
|
413
|
+
const event = components[0]!.components[0]!;
|
|
414
|
+
const start = event.properties.find((property) => property.name === "DTSTART")!;
|
|
415
|
+
start.parameters.TZID; // ["Europe/Berlin"]
|
|
416
|
+
start.value; // "20261014T100000", as written
|
|
417
|
+
|
|
418
|
+
const ics = stringifyIcsComponents(components);
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
A component has its `name`, `properties`, nested `components` and `line`. A property has its
|
|
422
|
+
`name`, `parameters` (each a list of values), its raw `value` and its `line`. Names are
|
|
423
|
+
upper-cased.
|
|
424
|
+
|
|
425
|
+
`stringifyIcsComponents(tree)` writes a tree back as text, with CRLF line ends and lines folded at
|
|
426
|
+
75 octets. It throws a `RangeError` for a name or value that contains a line break, which iCalendar
|
|
427
|
+
can't hold; escape line breaks in TEXT values as `\n` first.
|
|
428
|
+
|
|
429
|
+
### Values
|
|
430
|
+
|
|
431
|
+
These turn a raw value into a typed one and back, for any RFC 5545 value type:
|
|
432
|
+
|
|
433
|
+
```ts
|
|
434
|
+
import { decodeIcsDateValue, decodeIcsValue, encodeIcsValue } from "@moltenship/ics";
|
|
435
|
+
|
|
436
|
+
decodeIcsValue("DURATION", "PT1H30M");
|
|
437
|
+
// { ok: true, value: Temporal.Duration PT1H30M }
|
|
438
|
+
decodeIcsValue("INTEGER", "ten");
|
|
439
|
+
// { ok: false, message: "\"ten\" isn't an INTEGER" }
|
|
440
|
+
decodeIcsValue("DATE-TIME", "20261014T100000", { tzid: "Europe/Berlin" });
|
|
441
|
+
// { ok: true, value: { kind: "zoned", … } }
|
|
442
|
+
decodeIcsDateValue("20261019", "DATE-TIME");
|
|
443
|
+
// { ok: true, value: { kind: "date", … }, warnings: [{ code: "invalid-value" }] }
|
|
444
|
+
|
|
445
|
+
encodeIcsValue("TEXT", "Room 4.01, Berlin office"); // "Room 4.01\, Berlin office"
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
- `decodeIcsValue(type, raw, context)` decodes one value. It never throws: it returns
|
|
449
|
+
`{ ok: false, message }`, or `{ ok: true, value }` with `warnings` when it read the value
|
|
450
|
+
leniently. Each warning has the `code` that `parseIcs` would report it under.
|
|
451
|
+
- `context` gives a DATE-TIME its `tzid`, and a `resolveTimeZone(tzid)` function for TZIDs that
|
|
452
|
+
aren't IANA ids. Without one, only ids Temporal knows resolve; Windows names stay `unresolved`.
|
|
453
|
+
- `decodeIcsDateValue(raw, declared, context)` reads a DATE or DATE-TIME by its shape, as the
|
|
454
|
+
typed model does for `DTSTART`, `DTEND` and `EXDATE`, so a date written without `VALUE=DATE`
|
|
455
|
+
still reads as a date.
|
|
456
|
+
- `splitIcsValues(type, raw)` splits a list value, such as `CATEGORIES` or `EXDATE`, on its
|
|
457
|
+
separating commas, leaving escaped commas alone. `decodeIcsValues(type, raw, context)` splits and
|
|
458
|
+
decodes each item, so one bad item doesn't lose the others.
|
|
459
|
+
- `icsValueTypeOf(property)` says which type a property's value is: its `VALUE` parameter, else
|
|
460
|
+
the property's default type in RFC 5545, else TEXT.
|
|
461
|
+
- `encodeIcsValue(type, value)` writes a value as raw text. It throws a `RangeError` for values
|
|
462
|
+
iCalendar can't write, such as a duration in months. A zoned date-time is written as its wall
|
|
463
|
+
time; adding the `TZID` parameter is up to you.
|
|
464
|
+
|
|
465
|
+
### What the typed model doesn't map
|
|
466
|
+
|
|
467
|
+
Typed components keep what they don't understand. `otherProperties` holds every property no field
|
|
468
|
+
or extension claims, in the order of the text, and `otherComponents` holds unknown subcomponents.
|
|
469
|
+
On attendees and the organizer, `otherParameters` holds parameters such as Google's
|
|
470
|
+
`X-NUM-GUESTS`. All three are in the raw syntax layer's shapes, so the value functions above decode
|
|
471
|
+
them.
|
|
472
|
+
|
|
473
|
+
## Not included yet
|
|
474
|
+
|
|
475
|
+
- **Writing ICS from typed objects.** `stringifyIcsComponents` writes a syntax tree, which you
|
|
476
|
+
build yourself.
|
|
477
|
+
- **Recurrence expansion.** Rules are parsed into `IcsRecurrenceRule`, not expanded into
|
|
478
|
+
occurrences. [`@moltenship/calendar-recurrence`](../recurrence/reference.md) expands them, so this
|
|
479
|
+
package stays free of dependencies.
|
|
480
|
+
- **Byte input.** `parseIcs` takes a string. Decode bytes as UTF-8 first, for example with
|
|
481
|
+
`response.text()` or `new TextDecoder().decode(bytes)`. A line fold that splits a multi-byte
|
|
482
|
+
character can't be repaired after decoding.
|
package/docs/ics.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
What @moltenship/ics is, how to install it, and a first parse of iCalendar text into Temporal values.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/ics
|
|
6
|
+
|
|
7
|
+
`@moltenship/ics` reads iCalendar (RFC 5545), the text format of calendar feeds, invitations and
|
|
8
|
+
exports from Google Calendar, Outlook, iCloud and most other calendar apps. ICS text goes in.
|
|
9
|
+
Calendars, events, to-dos, journals, free/busy and time zones come out, with dates and times as
|
|
10
|
+
`Temporal` values and every problem in the text listed with its line.
|
|
11
|
+
|
|
12
|
+
## Use it without the calendar
|
|
13
|
+
|
|
14
|
+
The package imports no other Moltenship package, no UI framework and no dependency. It runs
|
|
15
|
+
wherever `Temporal` does: in a browser, on a server, in a worker or in a script. An app that never
|
|
16
|
+
renders a calendar can use it to read a feed, check an upload or convert an export.
|
|
17
|
+
|
|
18
|
+
`@moltenship/calendar` doesn't re-export it, so install it by its own name.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
**pnpm**
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @moltenship/ics
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**npm**
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @moltenship/ics
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**yarn**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
yarn add @moltenship/ics
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**bun**
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bun add @moltenship/ics
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The package is versioned with the calendar.
|
|
47
|
+
|
|
48
|
+
It needs a runtime with `Temporal`, or a polyfill loaded first, and TypeScript's `ESNext` library.
|
|
49
|
+
[Installation](./installation.md#temporal) shows both.
|
|
50
|
+
|
|
51
|
+
## Parse a calendar
|
|
52
|
+
|
|
53
|
+
`parseIcs` takes the text and returns its calendars. `getEventEnd` works out when an event ends,
|
|
54
|
+
from its `DTEND` or its `DURATION`:
|
|
55
|
+
|
|
56
|
+
```ts title="describe-events.ts"
|
|
57
|
+
import { getEventEnd, parseIcs, type IcsDateValue } from "@moltenship/ics";
|
|
58
|
+
|
|
59
|
+
export const text = `BEGIN:VCALENDAR
|
|
60
|
+
VERSION:2.0
|
|
61
|
+
PRODID:-//Example//Team//EN
|
|
62
|
+
BEGIN:VEVENT
|
|
63
|
+
UID:planning@example.com
|
|
64
|
+
DTSTAMP:20261001T080000Z
|
|
65
|
+
DTSTART;TZID=Europe/Berlin:20261012T090000
|
|
66
|
+
DURATION:PT45M
|
|
67
|
+
SUMMARY:Planning
|
|
68
|
+
END:VEVENT
|
|
69
|
+
BEGIN:VEVENT
|
|
70
|
+
UID:offsite@example.com
|
|
71
|
+
DTSTAMP:20261001T080000Z
|
|
72
|
+
DTSTART;VALUE=DATE:20261015
|
|
73
|
+
DTEND;VALUE=DATE:20261017
|
|
74
|
+
SUMMARY:Offsite
|
|
75
|
+
END:VEVENT
|
|
76
|
+
END:VCALENDAR`;
|
|
77
|
+
|
|
78
|
+
// A date or a time, as the file wrote it.
|
|
79
|
+
function show(value: IcsDateValue): string {
|
|
80
|
+
switch (value.kind) {
|
|
81
|
+
case "date":
|
|
82
|
+
return value.date.toString();
|
|
83
|
+
case "utc":
|
|
84
|
+
return value.instant.toString();
|
|
85
|
+
case "zoned":
|
|
86
|
+
return value.zoned.toString();
|
|
87
|
+
case "floating":
|
|
88
|
+
case "unresolved":
|
|
89
|
+
return value.wallTime.toString();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function describeEvents(ics: string): string[] {
|
|
94
|
+
const { calendars } = parseIcs(ics);
|
|
95
|
+
const events = calendars[0]?.events ?? [];
|
|
96
|
+
// getEventEnd reads DTEND, or adds DURATION to the start.
|
|
97
|
+
return events.map(
|
|
98
|
+
(event) => `${event.summary}: ${show(event.start)} to ${show(getEventEnd(event))}`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`describeEvents(text)` returns these lines:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
Planning: 2026-10-12T09:00:00+02:00[Europe/Berlin] to 2026-10-12T09:45:00+02:00[Europe/Berlin]
|
|
107
|
+
Offsite: 2026-10-15 to 2026-10-17
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The first event names a time zone, so its start is a `Temporal.ZonedDateTime`. The second is an
|
|
111
|
+
all-day event, so its start is a `Temporal.PlainDate`, and its end is the day after its last day,
|
|
112
|
+
as the file wrote it. A start's `kind` says which of five shapes the file used, and
|
|
113
|
+
[Dates and times](./ics/reference.md#dates-and-times) lists them.
|
|
114
|
+
|
|
115
|
+
## Try it
|
|
116
|
+
|
|
117
|
+
Edit the text below to see what `parseIcs` returns. The sample is a Google Calendar feed with a
|
|
118
|
+
recurring meeting, an all-day event, an event imported from Outlook, and one date written the way
|
|
119
|
+
a careless exporter writes it.
|
|
120
|
+
|
|
121
|
+
> Live example: see it at https://time.molten.sh/docs/react/ics
|
|
122
|
+
|
|
123
|
+
## What it does with bad text
|
|
124
|
+
|
|
125
|
+
Parsing is lenient. The parser keeps what it can read, skips a component it can't type, such as an
|
|
126
|
+
event without `UID` or `DTSTART`, and reports each problem in `issues` with its line. Bad text
|
|
127
|
+
never throws. With `strict: true`, an error throws an `IcsParseError` instead.
|
|
128
|
+
[Read an .ics file](./ics/import.md) shows both ways.
|
|
129
|
+
|
|
130
|
+
## What it doesn't do
|
|
131
|
+
|
|
132
|
+
- **It doesn't expand recurring events.** A rule is parsed into an `IcsRecurrenceRule`, and its
|
|
133
|
+
occurrences aren't listed. [`@moltenship/calendar-recurrence`](./recurrence.md) lists them.
|
|
134
|
+
- **It doesn't write ICS from typed objects.** `stringifyIcsComponents` writes a syntax tree you
|
|
135
|
+
build yourself.
|
|
136
|
+
- **It doesn't read bytes.** `parseIcs` takes a string, so decode the bytes as UTF-8 first.
|
|
137
|
+
|
|
138
|
+
## Next
|
|
139
|
+
|
|
140
|
+
- [Read an .ics file](./ics/import.md): Parse a file a person picks, report its problems, and turn its dates into instants.
|
|
141
|
+
- [Show an ICS feed](./ics/feed.md): Fetch a feed on the server and show its events in the calendar.
|
|
142
|
+
- [API reference](./ics/reference.md): Every field of a calendar and an event, time zones, issues, extensions and the lower layers.
|