02examples

ICS import and export

Drop a .ics feed onto the calendar, then export the visible week back out as a file.

An empty calendar and three buttons. "Import sample feed" parses a small team feed — two offsites, a bank holiday, a weekly sync, a product demo — and adds what it can, then lists what it refused and why. Open or drop your own .ics and the same happens to it. "Export visible week" serialises every event in the range back to a file, and shows the text so the round trip is visible without opening the download.

liveICS import and exportparseICSeventsToICSrangeOfViewdownloadICS
loading

How it works

  • parseICS(text, { color }) never throws. It returns events ready for the store plus skipped (dropped, with a reason) and warnings (kept, but approximated). The sample feed carries one of each kind on purpose: a VALARM (reminders are not imported), a STATUS:CANCELLED event, an X- vendor property, and a DTSTART;TZID=… that is read as local wall-clock time and preserved on timeZone. See ICS.
  • A UID becomes the event id, so importing the same feed twice is idempotent: the panel filters out ids the store already has and adds the rest with one store.batch, which is one committed change and one undo step.
  • A dropped file is read with File.text(); the drop zone is the whole bar, and the file input under "Open your own .ics" is the keyboard-reachable route to the same function.
  • Export takes the visible range from useKloq().view through rangeOfView, keeps every event that expandRecurrence places inside it (a series counts if any occurrence does; the master goes out with its RRULE), and serialises them with eventsToICS, which folds the per-event toICS output into one VCALENDAR. For a single event, downloadICS(event) does the download in one call.
  • The feed in data.ts is built from the current week so it always lands where you are looking. Times are floating local time; all-day events use date-only values with the exclusive DTEND the spec — and CalEvent — require.

Take it further

Copy and paste speak the same format: eventsToICS / parseClipboardEvents are what ⌘C and ⌘V use, so events copied here paste into any calendar app that accepts ICS, and back. Wire parseICS to a URL fetch and you have a subscription; wire the export to onCommit and every change streams out — see Optimistic sync.

on this page