Kantoor.Dav.Ical (Kantoor v1.0.0)

Small helpers for reading and editing iCalendar documents with the Dav library's structural parser (Dav.Cal.ICalendar). Edits keep every property they do not touch, so a task or event made on a phone survives a round trip through the web UI (alarms, X- properties, attendees' answers...).

Times are handled as wall-clock values: {:date, Date} or {:naive, NaiveDateTime, zone} with zone one of :floating, :utc or {:tzid, name}. The zone is only remembered so a rewritten property keeps it.

Summary

Functions

A new calendar wrapping one component.

The first component named name without a RECURRENCE-ID (else the first).

Removes every property named name.

Encodes a moment as {value, parameters} for a property.

A mailto: calendar user address for a bare address.

Reads a date or date-time property as a wall-clock moment.

A fresh UID.

Parses a document, :error when it is not iCalendar.

A property, or nil.

Every property named name.

Replaces (or adds) the single property name; nil value removes it.

Replaces the first component named name of a calendar with component.

The events of a calendar grouped by UID, in the order they first appear: a list of {uid, calendar}, each calendar holding only that UID's events (a series and its overrides stay together) and every VTIMEZONE. An event with no UID is a group of its own with nil. At most max groups are returned; skipped counts the events left out.

The date part of a moment.

The wall-clock NaiveDateTime of a moment (midnight for a date).

The UTC timestamp format used by DTSTAMP, COMPLETED and LAST-MODIFIED.

A property's value, or nil when absent or empty.

Writes a calendar to iCalendar text.

Types

moment()

@type moment() :: {:date, Date.t()} | {:naive, NaiveDateTime.t(), zone()}

zone()

@type zone() :: :floating | :utc | {:tzid, String.t()}

Functions

calendar(component)

@spec calendar(map()) :: map()

A new calendar wrapping one component.

component(calendar, name)

@spec component(map(), String.t()) :: map() | nil

The first component named name without a RECURRENCE-ID (else the first).

drop(component, name)

@spec drop(map(), String.t()) :: map()

Removes every property named name.

encode(arg)

@spec encode(moment()) :: {String.t(), map()}

Encodes a moment as {value, parameters} for a property.

mailto(address)

A mailto: calendar user address for a bare address.

moment(arg1)

@spec moment(map() | nil) :: moment() | nil

Reads a date or date-time property as a wall-clock moment.

new_uid()

A fresh UID.

parse(body)

@spec parse(binary()) :: {:ok, map()} | :error

Parses a document, :error when it is not iCalendar.

Works around a bug in the DAV library's TEXT unescaping: it leaves \; in values (its "\;" replacement is a no-op), so a parse-edit-write round trip doubles backslashes before semicolons. Detected at runtime, so it switches itself off once the library is fixed.

prop(component, name)

@spec prop(map(), String.t()) :: map() | nil

A property, or nil.

props(component, name)

@spec props(map(), String.t()) :: [map()]

Every property named name.

put(component, name, value, params)

@spec put(map(), String.t(), String.t() | nil, map()) :: map()

Replaces (or adds) the single property name; nil value removes it.

replace_component(calendar, component)

@spec replace_component(map(), map()) :: map()

Replaces the first component named name of a calendar with component.

split_events(calendar, max)

@spec split_events(map(), pos_integer()) ::
  {[{String.t() | nil, map()}], non_neg_integer()}

The events of a calendar grouped by UID, in the order they first appear: a list of {uid, calendar}, each calendar holding only that UID's events (a series and its overrides stay together) and every VTIMEZONE. An event with no UID is a group of its own with nil. At most max groups are returned; skipped counts the events left out.

RFC 5546 allows several events in one iTIP message only when they share a UID (section 3.2.2, REQUEST), so a message holding different UIDs is several invitations in one envelope; each is handled alone.

to_date(arg1)

@spec to_date(moment() | nil) :: Date.t() | nil

The date part of a moment.

to_naive(arg1)

@spec to_naive(moment() | nil) :: NaiveDateTime.t() | nil

The wall-clock NaiveDateTime of a moment (midnight for a date).

utc_stamp(dt)

@spec utc_stamp(DateTime.t()) :: String.t()

The UTC timestamp format used by DTSTAMP, COMPLETED and LAST-MODIFIED.

value(component, name)

@spec value(map(), String.t()) :: String.t() | nil

A property's value, or nil when absent or empty.

write(calendar)

@spec write(map()) :: binary()

Writes a calendar to iCalendar text.