ical API reference
Build and parse iCalendar (RFC 5545): a Calendar holding Events (VEVENT) and Todos (VTODO), encoded to a VCALENDAR and parsed back. Pure Jennifer over strings / lists + time - no Go, no system engine.
Beyond the basics (UID / SUMMARY / DESCRIPTION / LOCATION), an event supports recurrence (RRULE / RDATE / EXDATE, with an occurrences expander for FREQ / INTERVAL / COUNT / UNTIL), DURATION, all-day dates (VALUE=DATE) and a named-zone TZID, an ORGANIZER and ATTENDEEs, and VALARM alarms. Times go through time: UTC values write as 20240615T130000Z; a TZID event stores its wall clock as a floating value paired with the zone name (because time models fixed-offset zones only, add a matching VTIMEZONE for a strict consumer). Text values are RFC 5545-escaped and content lines folded at 75 octets, so parse(encode(cal)) round-trips; parse throws an IcalError for malformed input.
Import with import "ical.j" as ical;. See the ical guide for prose and examples.
Contents
| Name | What it is |
|---|---|
add | A copy of the calendar with an event appended (value-semantic). |
addAlarm | A copy of the event with a VALARM appended. |
addAttendee | A copy of the event with an ATTENDEE appended. |
addExdate | A copy of the event with an excluded recurrence instant (EXDATE) appended. |
addRdate | A copy of the event with an extra recurrence instant (RDATE) appended. |
addTodo | A copy of the calendar with a to-do appended. |
alarm | An alarm (VALARM). |
attendee | An attendee. |
calendar | A calendar with the default Jennifer PRODID and no events. |
calendarWith | A calendar with a caller-supplied PRODID. |
describe | A copy of the event with its description set (value-semantic). |
describeTodo | A copy of the to-do with its DESCRIPTION set. |
encode | Render a calendar to iCalendar text (RFC 5545): a VCALENDAR wrapping one VEVENT per event (and a... |
event | An event. |
locate | A copy of the event with its location set (value-semantic). |
occurrences | Expand an event's recurrence set into up to max occurrence instants, sorted and without duplicates:... |
parse | Parse iCalendar text into a Calendar. |
recur | A copy of the event with a recurrence rule (RRULE). |
rule | Build a simple RRULE value from a frequency, interval, and count. |
todo | A to-do (VTODO). |
withAllDay | A copy of the event marked (or unmarked) as an all-day event. |
withDue | A copy of the to-do with its DUE instant set. |
withOrganizer | A copy of the event with its ORGANIZER set. |
withStatus | A copy of the to-do with its STATUS set (e.g. |
withZone | A copy of the event with its time-zone id (TZID) set, so DTSTART / DTEND encode as local time in that... |
Alarm | struct: An event alarm (VALARM). |
Attendee | struct: An event attendee (ATTENDEE). |
Calendar | struct: A calendar: a product identifier, its events, and its to-dos. |
Event | struct: A single calendar event (a VEVENT). |
IcalError | struct: A malformed calendar or recurrence rule. |
Todo | struct: A to-do item (a VTODO). |
Functions
add
ical.add(cal as Calendar, ev as Event)A copy of the calendar with an event appended (value-semantic).
cal- the calendar
ev- the event to add
- Returns
Calendar - a fresh calendar with the event appended
addAlarm
ical.addAlarm(ev as Event, a as Alarm)A copy of the event with a VALARM appended.
ev- the event
a- the alarm
- Returns
Event - a fresh event with the alarm added
addAttendee
ical.addAttendee(ev as Event, a as Attendee)A copy of the event with an ATTENDEE appended.
ev- the event
a- the attendee
- Returns
Event - a fresh event with the attendee added
addExdate
ical.addExdate(ev as Event, t as time.Time)A copy of the event with an excluded recurrence instant (EXDATE) appended.
ev- the event
t- the excluded instant
- Returns
Event - a fresh event with the EXDATE added
addRdate
ical.addRdate(ev as Event, t as time.Time)A copy of the event with an extra recurrence instant (RDATE) appended.
ev- the event
t- the extra instant
- Returns
Event - a fresh event with the RDATE added
addTodo
ical.addTodo(cal as Calendar, td as Todo)A copy of the calendar with a to-do appended.
cal- the calendar
td- the to-do to add
- Returns
Calendar - a fresh calendar with the to-do appended
alarm
ical.alarm(action as string, trigger as string, description as string)An alarm (VALARM).
action- the action ("DISPLAY" / "AUDIO" / "EMAIL")
trigger- the trigger value (e.g.
-PT15M) description- the reminder text ("" for none)
- Returns
Alarm - the alarm
attendee
ical.attendee(address as string, cn as string, role as string)An attendee.
address- the calendar address (e.g.
mailto:bob@example.com) cn- the common name ("" for none)
role- the role ("" for none; e.g. "REQ-PARTICIPANT")
- Returns
Attendee - the attendee
calendar
ical.calendar()A calendar with the default Jennifer PRODID and no events.
- Returns
Calendar - the empty calendar
calendarWith
ical.calendarWith(prodid as string)A calendar with a caller-supplied PRODID.
prodid- the product identifier
- Returns
Calendar - the empty calendar
describe
ical.describe(ev as Event, description as string)A copy of the event with its description set (value-semantic).
ev- the event
description- the description text
- Returns
Event - a fresh event with the description set
describeTodo
ical.describeTodo(td as Todo, description as string)A copy of the to-do with its DESCRIPTION set.
td- the to-do
description- the description
- Returns
Todo - a fresh to-do with the description set
encode
ical.encode(cal as Calendar)Render a calendar to iCalendar text (RFC 5545): a VCALENDAR wrapping one VEVENT per event (and a VTODO per to-do), CRLF line endings, escaped text, folded long lines. Optional properties (DESCRIPTION / LOCATION / recurrence / organizer / attendees / alarms) are emitted only when set.
cal- the calendar to encode
- Returns
string - the iCalendar text (CRLF-terminated)
event
ical.event(
uid as string,
start as time.Time,
end as time.Time,
summary as string)An event. DTSTAMP defaults to the start; the optional fields (DESCRIPTION / LOCATION / recurrence / organizer / attendees / alarms) are empty until set with the describe / locate / recur / ... builders.
uid- the unique identifier
start- the start instant
end- the end instant
summary- the title
- Returns
Event - the event
locate
ical.locate(ev as Event, location as string)A copy of the event with its location set (value-semantic).
ev- the event
location- the location text
- Returns
Event - a fresh event with the location set
occurrences
ical.occurrences(ev as Event, max as int)Expand an event's recurrence set into up to max occurrence instants, sorted and without duplicates: DTSTART, the RRULE series from it (FREQ SECONDLY ... YEARLY, INTERVAL, COUNT, UNTIL), and the RDATEs, minus the EXDATEs. A MONTHLY / YEARLY instance whose date does not exist (Jan 31 + 1 month, Feb 29 in a common year) is skipped and not counted, as RFC 5545 requires. The BY* parts are not expanded: a rule holding one throws rather than yield wrong instants.
ev- the event
max- the maximum number of occurrences to return
- Returns
list of time.Time - the occurrence instants (at most
max) - Throws
IcalError - kind "ical" for a malformed or unsupported
RRULE, or a series that runs past the representable time range - Throws
Error - kind "limit" when reaching
maxtakes more than 100000 recurrence steps
parse
ical.parse(text as string)Parse iCalendar text into a Calendar. Unfolds folded lines and reads the PRODID, each VEVENT (UID / DTSTAMP / DTSTART / DTEND / DURATION / SUMMARY / DESCRIPTION / LOCATION, the all-day VALUE=DATE and TZID parameters, RRULE / RDATE / EXDATE, ORGANIZER / ATTENDEE, and nested VALARMs), and each VTODO. A VTIMEZONE and other components are checked for structure and skipped. An event with no DTSTART is skipped; one with neither DTEND nor DURATION ends at its start (a DATE start: one day later).
text- the iCalendar text: one or more
VCALENDARs - Returns
Calendar - the parsed calendar
- Throws
IcalError - kind "ical" for malformed input: no
VCALENDAR, a line without a:, a property outside a component, a missing or mismatchedEND, an invalid TEXT escape, a malformed or impossible date, a malformedDURATION,DTENDtogether withDURATION, or an end before the start
recur
ical.recur(ev as Event, rrule as string)A copy of the event with a recurrence rule (RRULE). Pass a raw RRULE value (e.g. "FREQ=WEEKLY;COUNT=10") or build one with rule.
ev- the event
rrule- the RRULE value
- Returns
Event - a fresh recurring event
rule
ical.rule(freq as string, interval as int, count as int)Build a simple RRULE value from a frequency, interval, and count. INTERVAL is omitted when 1 and COUNT when 0 (i.e. unbounded).
freq- the frequency ("DAILY" / "WEEKLY" / "MONTHLY" / "YEARLY")
interval- the interval (every N periods; 1 = every period)
count- the number of occurrences (0 = unbounded)
- Returns
string - the RRULE value
todo
ical.todo(uid as string, stamp as time.Time, summary as string)A to-do (VTODO). DTSTAMP defaults to stamp; DUE / STATUS / DESCRIPTION are set with the builders.
uid- the unique identifier
stamp- the
DTSTAMP summary- the title
- Returns
Todo - the to-do
withAllDay
ical.withAllDay(ev as Event, isAllDay as bool)A copy of the event marked (or unmarked) as an all-day event. All-day DTSTART / DTEND encode as VALUE=DATE (a bare YYYYMMDD).
ev- the event
isAllDay- whether the event is all-day
- Returns
Event - a fresh event with the all-day flag set
withDue
ical.withDue(td as Todo, due as time.Time)A copy of the to-do with its DUE instant set.
td- the to-do
due- the due instant
- Returns
Todo - a fresh to-do with the due date set
withOrganizer
ical.withOrganizer(ev as Event, address as string)A copy of the event with its ORGANIZER set.
ev- the event
address- the calendar address (e.g.
mailto:a@example.com) - Returns
Event - a fresh event with the organizer set
withStatus
ical.withStatus(td as Todo, status as string)A copy of the to-do with its STATUS set (e.g. "NEEDS-ACTION" / "COMPLETED").
td- the to-do
status- the status
- Returns
Todo - a fresh to-do with the status set
withZone
ical.withZone(ev as Event, tzid as string)A copy of the event with its time-zone id (TZID) set, so DTSTART / DTEND encode as local time in that zone (DTSTART;TZID=America/New_York:...) instead of UTC. The named zone is preserved verbatim; add a matching VTIMEZONE for a strict consumer.
ev- the event
tzid- the IANA time-zone name (e.g. "Europe/London"); "" restores UTC
- Returns
Event - a fresh event with the time zone set
Structs
Alarm
An event alarm (VALARM).
def struct Alarm {
action as string,
trigger as string,
description as string
};action- the
ACTION("DISPLAY" / "AUDIO" / "EMAIL") trigger- the
TRIGGERvalue (e.g.-PT15M= 15 minutes before) description- the
DESCRIPTION(the reminder text; "" when unset)
Attendee
An event attendee (ATTENDEE).
def struct Attendee {
address as string,
cn as string,
role as string
};address- the calendar address (e.g.
mailto:bob@example.com) cn- the common name (
CNparameter; "" when unset) role- the participation role (
ROLE; e.g. "REQ-PARTICIPANT"; "" when unset)
Calendar
A calendar: a product identifier, its events, and its to-dos.
def struct Calendar {
prodid as string,
events as list of Event,
todos as list of Todo
};prodid- the
PRODIDproduct identifier events- the calendar's events
todos- the calendar's to-dos (
VTODOs)
Event
A single calendar event (a VEVENT).
def struct Event {
uid as string,
stamp as time.Time,
start as time.Time,
end as time.Time,
summary as string,
description as string,
location as string,
allDay as bool,
tzid as string,
rrule as string,
rdates as list of time.Time,
exdates as list of time.Time,
organizer as string,
attendees as list of Attendee,
alarms as list of Alarm
};uid- the globally-unique
UID stamp- the
DTSTAMP(creation / last-modified instant) start- the
DTSTARTstart instant end- the
DTENDend instant summary- the
SUMMARY(title) description- the
DESCRIPTION("" when unset) location- the
LOCATION("" when unset) allDay- whether the event is an all-day event (
VALUE=DATE) tzid- the
TZIDtime-zone name for a localDTSTART/DTEND("" = UTC) rrule- the
RRULErecurrence rule value ("" when non-recurring) rdates- extra recurrence instants (
RDATE) exdates- excluded recurrence instants (
EXDATE) organizer- the
ORGANIZERcalendar address ("" when unset) attendees- the
ATTENDEEs alarms- the event's
VALARMs
IcalError
A malformed calendar or recurrence rule. Every error of kind "ical" is one, so its fields are safe to read once the kind matches.
def struct IcalError {
kind as string,
message as string,
line as int
};kind- always
"ical" message- what is wrong, prefixed
line N:when tied to a line line- the 1-based physical line of
parse's input the fault is on (a folded line counts from its first physical line); 0 when the fault is not tied to a line (anoccurrencesrule, input with noVCALENDAR)
Todo
A to-do item (a VTODO).
def struct Todo {
uid as string,
stamp as time.Time,
summary as string,
due as time.Time,
hasDue as bool,
description as string,
status as string
};uid- the globally-unique
UID stamp- the
DTSTAMP summary- the
SUMMARY due- the
DUEinstant (valid only whenhasDue) hasDue- whether a
DUEis set description- the
DESCRIPTION("" when unset) status- the
STATUS(e.g. "NEEDS-ACTION" / "COMPLETED"; "" when unset)