02examples
ICS import and export
Drop a .ics feed onto the calendar, then export what is on screen 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. If none of them fall in
the range on screen — a single day, in a narrow box — the calendar moves to
the first one. Open or drop your own .ics and the same happens to it. The
third button is named for the view you are in, "Export visible week" or
"Export visible day", and serialises every event in that range back to a
file; with nothing in range it says so and downloads nothing. Either way the
result and the ICS text land under the grid, so the round trip is visible
without opening the download.
liveICS import and export
uses
How it works
parseICS(text, { color })never throws. It returnseventsready for the store plusskipped(dropped, with a reason) andwarnings(kept, but approximated). The sample feed carries one of each kind on purpose: aVALARM(reminders are not imported), aSTATUS:CANCELLEDevent, anX-vendor property, and aDTSTART;TZID=…that is read as local wall-clock time and preserved ontimeZone. See ICS.- A
UIDbecomes the eventid, so importing the same feed twice is idempotent: the bar filters out ids the store already has and adds the rest with onestore.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 "Open your own .ics" button is the keyboard-reachable route to the same function. useKloq().viewSettingnames the button anduseKloq().view, throughrangeOfView, is the range it exports. Export keeps every event thatexpandRecurrenceplaces inside it (a series counts if any occurrence does; the master goes out with itsRRULE), and serialises them witheventsToICS, which folds the per-eventtoICSoutput into oneVCALENDAR. For a single event,downloadICS(event)does the download in one call.- The feed in
data.tsis built from the current week. After an import the bar checks the samerangeOfViewand callsk.goToDatewhen nothing landed in it. Times are floating local time; all-day events use date-only values with the exclusiveDTENDthe spec — andCalEvent— 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.