Scheduler · Data
Import an .ics calendar
parseIcs turns an iCalendar file — an export from Google Calendar, Outlook or Apple Calendar — into events: all-day and timed, time zones, recurring rules and their exceptions.
Live demo
Find the standup that's missing on one day · Open an .ics file of your own
Fullscreenimport { useState } from "react"
import { parseIcs, ProScheduler, type SchedulerEvent } from "@andreisaac/pro-scheduler"
import { sampleIcs } from "./data/integrations"
import { Choice, Toolbar, useEvents } from "./kit"
export function IcsImportDemo() {
const { events, setEvents, handlers } = useEvents<SchedulerEvent>(() => parseIcs(sampleIcs()))
const [note, setNote] = useState(`Imported ${events.length} events from the sample calendar.`)
const load = (text: string, name: string) => {
const imported = parseIcs(text)
setEvents(imported)
setNote(`Imported ${imported.length} events from ${name}.`)
}
return (
<>
<Toolbar label="Import">
<Choice onClick={() => load(sampleIcs(), "the sample calendar")}>Load sample</Choice>
<label className="docs-demo__file">
Open an .ics file…
<input
type="file"
accept=".ics,text/calendar"
className="sr-only"
onChange={async (e) => {
const file = e.target.files?.[0]
if (file) load(await file.text(), file.name)
e.target.value = ""
}}
/>
</label>
<span className="text-sm text-muted-foreground" aria-live="polite">
{note}
</span>
</Toolbar>
<ProScheduler
data={events}
view={{ scheduler: { type: "week", startTime: "07:00", endTime: "20:00" } }}
height={600}
{...handlers}
/>
</>
)
}// data/integrations.ts — sample data, relative to the current week or month.
const p2 = (n: number) => String(n).padStart(2, "0")
/** iCalendar DATE-TIME (floating) for day `day` from today, at `h:m`. */
function icsAt(day: number, h: number, m = 0) {
const d = new Date()
d.setDate(d.getDate() + day)
return `${d.getFullYear()}${p2(d.getMonth() + 1)}${p2(d.getDate())}T${p2(h)}${p2(m)}00`
}
function icsDay(day: number) {
return icsAt(day, 0).slice(0, 8)
}
/** A weekday of this week other than today (later if possible), so the skipped
* standup is visible in the opening week view. */
function nextWeekdayOffset() {
const monday = -((new Date().getDay() + 6) % 7)
const weekdays = [0, 1, 2, 3, 4].map((i) => monday + i).filter((offset) => offset !== 0)
// The series starts 3 days ago, so an exception before that would never show.
return weekdays.find((offset) => offset > 0) ?? weekdays.filter((offset) => offset >= -3).pop() ?? 1
}
/** A small calendar export: timed, all-day, recurring (with an exception) and a zoned event. */
export function sampleIcs(): string {
return [
"BEGIN:VCALENDAR",
"VERSION:2.0",
"PRODID:-//ProScheduler demo//EN",
"BEGIN:VEVENT",
"UID:team-standup",
"SUMMARY:Team standup",
`DTSTART:${icsAt(-3, 9, 30)}`,
`DTEND:${icsAt(-3, 9, 45)}`,
"RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR",
`EXDATE:${icsAt(nextWeekdayOffset(), 9, 30)}`,
"END:VEVENT",
"BEGIN:VEVENT",
"UID:design-review",
"SUMMARY:Design review",
"DESCRIPTION:Walk through the new booking flow\\, then decide.",
"LOCATION:Room 4",
`DTSTART:${icsAt(1, 14)}`,
"DURATION:PT1H30M",
"END:VEVENT",
"BEGIN:VEVENT",
"UID:offsite",
"SUMMARY:Team offsite",
`DTSTART;VALUE=DATE:${icsDay(3)}`,
`DTEND;VALUE=DATE:${icsDay(5)}`,
"END:VEVENT",
"BEGIN:VEVENT",
"UID:ny-call",
"SUMMARY:Call with New York",
`DTSTART;TZID=America/New_York:${icsAt(0, 11)}`,
`DTEND;TZID=America/New_York:${icsAt(0, 12)}`,
"BEGIN:VALARM",
"TRIGGER:-PT10M",
"ACTION:DISPLAY",
"END:VALARM",
"END:VEVENT",
"END:VCALENDAR",
].join("\r\n")
}About this demo
parseIcs turns an iCalendar file — an export from Google Calendar, Outlook or Apple Calendar — into events: all-day and timed, time zones, recurring rules and their exceptions.
Things to try
- Find the standup that's missing on one day
- Open an .ics file of your own
The props behind it are explained in Output and scale.