Overview
What @moltenship/ics is, how to install it, and a first parse of iCalendar text into Temporal values.
@moltenship/ics reads iCalendar (RFC 5545), the text format of calendar feeds, invitations and
exports from Google Calendar, Outlook, iCloud and most other calendar apps. ICS text goes in.
Calendars, events, to-dos, journals, free/busy and time zones come out, with dates and times as
Temporal values and every problem in the text listed with its line.
Use it without the calendar
The package imports no other Moltenship package, no UI framework and no dependency. It runs
wherever Temporal does: in a browser, on a server, in a worker or in a script. An app that never
renders a calendar can use it to read a feed, check an upload or convert an export.
@moltenship/calendar doesn't re-export it, so install it by its own name.
Install
pnpm add @moltenship/icsThe package is versioned with the calendar.
It needs a runtime with Temporal, or a polyfill loaded first, and TypeScript's ESNext library.
Installation shows both.
Parse a calendar
parseIcs takes the text and returns its calendars. getEventEnd works out when an event ends,
from its DTEND or its DURATION:
import { getEventEnd, parseIcs, type IcsDateValue } from "@moltenship/ics";
export const text = `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Example//Team//EN
BEGIN:VEVENT
UID:planning@example.com
DTSTAMP:20261001T080000Z
DTSTART;TZID=Europe/Berlin:20261012T090000
DURATION:PT45M
SUMMARY:Planning
END:VEVENT
BEGIN:VEVENT
UID:offsite@example.com
DTSTAMP:20261001T080000Z
DTSTART;VALUE=DATE:20261015
DTEND;VALUE=DATE:20261017
SUMMARY:Offsite
END:VEVENT
END:VCALENDAR`;
// A date or a time, as the file wrote it.
function show(value: IcsDateValue): string {
switch (value.kind) {
case "date":
return value.date.toString();
case "utc":
return value.instant.toString();
case "zoned":
return value.zoned.toString();
case "floating":
case "unresolved":
return value.wallTime.toString();
}
}
export function describeEvents(ics: string): string[] {
const { calendars } = parseIcs(ics);
const events = calendars[0]?.events ?? [];
// getEventEnd reads DTEND, or adds DURATION to the start.
return events.map(
(event) => `${event.summary}: ${show(event.start)} to ${show(getEventEnd(event))}`,
);
}describeEvents(text) returns these lines:
Planning: 2026-10-12T09:00:00+02:00[Europe/Berlin] to 2026-10-12T09:45:00+02:00[Europe/Berlin]
Offsite: 2026-10-15 to 2026-10-17The first event names a time zone, so its start is a Temporal.ZonedDateTime. The second is an
all-day event, so its start is a Temporal.PlainDate, and its end is the day after its last day,
as the file wrote it. A start's kind says which of five shapes the file used, and
Dates and times lists them.
Try it
Edit the text below to see what parseIcs returns. The sample is a Google Calendar feed with a
recurring meeting, an all-day event, an event imported from Outlook, and one date written the way
a careless exporter writes it.
What it does with bad text
Parsing is lenient. The parser keeps what it can read, skips a component it can't type, such as an
event without UID or DTSTART, and reports each problem in issues with its line. Bad text
never throws. With strict: true, an error throws an IcsParseError instead.
Read an .ics file shows both ways.
What it doesn't do
- It doesn't expand recurring events. A rule is parsed into an
IcsRecurrenceRule, and its occurrences aren't listed.@moltenship/calendar-recurrencelists them. - It doesn't write ICS from typed objects.
stringifyIcsComponentswrites a syntax tree you build yourself. - It doesn't read bytes.
parseIcstakes a string, so decode the bytes as UTF-8 first.