convert: JSCalendar and iCalendar conversion#
ical_to_jscal and jscal_to_ical convert between iCalendar text and JSCalendar dicts directly, with no JMAP client or network connection involved.
JSCalendar and iCalendar conversion utilities.
- Public API:
ical_to_jscal(ical_str, calendar_id=None) -> dict jscal_to_ical(jscal) -> str
iCalendar to JSCalendar conversion (RFC 5545 to RFC 8984).
- Public API:
ical_to_jscal(ical_str, calendar_id=None) -> dict
The output dict is a raw JSCalendar CalendarEvent object suitable for passing directly to CalendarEvent/set.
- calendaring_jmap.convert.ical_to_jscal.ical_to_jscal(ical_str: str, calendar_id: str | None = None) dict[source]#
Convert an iCalendar string to a JSCalendar CalendarEvent dict (RFC 8984).
Processes the first VEVENT found in the string. Any sibling VEVENTs with a RECURRENCE-ID are folded into the
recurrenceOverridesmap of the master event. EXDATE entries are also added torecurrenceOverrides.- Parameters:
ical_str – A VCALENDAR string (or bare VEVENT; fixup() normalises it).
calendar_id – If provided, sets
calendarIds: {calendar_id: true}on the output. Required when the result will be used inCalendarEvent/set(the server needs to know which calendar).
- Returns:
Raw JSCalendar dict suitable for passing directly to
CalendarEvent/set.- Raises:
ValueError – If no VEVENT component is found; the master VEVENT is missing
UIDorDTSTART(both mandatory per RFC 5545, but not every producer enforces this);DTSTART/DTENDhave mismatched value types, oneDATEand oneDATE-TIME(RFC 5545 Section 3.8.2.2 requires both to match, andDTENDto be later in time thanDTSTART); orDTEND/DURATIONresolves to beforeDTSTART(RFC 8984 Section 5.1.2 requiresdurationto be zero or positive).
JSCalendar to iCalendar conversion (RFC 8984 to RFC 5545).
- Public API:
jscal_to_ical(jscal: dict) -> str
Accepts a raw JSCalendar CalendarEvent dict (as returned by CalendarEvent/get or produced by ical_to_jscal). Returns a VCALENDAR string.
- calendaring_jmap.convert.jscal_to_ical.jscal_to_ical(jscal: dict) str[source]#
Convert a JSCalendar CalendarEvent dict to an iCalendar VCALENDAR string.
Handles the full set of fields supported by
ical_to_jscalfor round-trip fidelity.recurrenceOverridesentries withexcluded: truebecome EXDATE properties; patch dicts become child VEVENTs with RECURRENCE-ID.- Parameters:
jscal – A raw JSCalendar CalendarEvent dict as returned by
CalendarEvent/get.- Returns:
An iCalendar VCALENDAR string, normalised by
fixup.- Raises:
ValueError – If
uidis absent or empty (mandatory per RFC 8984 Section 4.1.2; a server response should always include it, but emitting anUID-less VEVENT, invalid per RFC 5545, would be a worse failure mode than raising here).