ICal.Recurrence (iCal v1.1.2)

View Source

Adds support for recurring events.

Events can recur by frequency, count, interval, and/or start/end date. To see the specific rules and examples, see add_recurring_events/2 below.

Summary

Functions

Given an event, return a stream of recurrences for that event.

Types

frequency()

@type frequency() ::
  :secondly | :minutely | :hourly | :daily | :weekly | :monthly | :yearly

t()

@type t() :: %ICal.Recurrence{
  by_day: [{offset :: integer(), byday :: weekday()}],
  by_hour: [non_neg_integer()],
  by_minute: [non_neg_integer()],
  by_month: [non_neg_integer()],
  by_month_day: [non_neg_integer()],
  by_second: [non_neg_integer()],
  by_set_position: [non_neg_integer()],
  by_week_number: [non_neg_integer()],
  by_year_day: [non_neg_integer()],
  count: integer(),
  frequency: frequency(),
  interval: integer(),
  until: DateTime.t() | nil,
  weekday: weekday()
}

weekday()

@type weekday() ::
  :monday | :tuesday | :wednesday | :thursday | :friday | :saturday | :sunday

Functions

stream(event)

@spec stream(%ICal.Event{
  alarms: term(),
  attachments: term(),
  attendees: term(),
  categories: term(),
  class: term(),
  comments: term(),
  contacts: term(),
  created: term(),
  custom_properties: term(),
  description: term(),
  dtend: term(),
  dtstamp: term(),
  dtstart: term(),
  duration: term(),
  exdates: term(),
  geo: term(),
  location: term(),
  modified: term(),
  organizer: term(),
  priority: term(),
  rdates: term(),
  recurrence_id: term(),
  related_to: term(),
  request_status: term(),
  resources: term(),
  rrule: term(),
  sequence: term(),
  status: term(),
  summary: term(),
  transparency: term(),
  uid: term(),
  url: term()
}) :: Enumerable.t()

Given an event, return a stream of recurrences for that event.

Warning: this may create a very large sequence of event recurrences.

Parameters

  • event: The event that may contain an rrule. See ICal.Event.

  • end_date (optional): A date time that represents the fallback end date for a recurring event. This value is only used when the options specified in rrule result in an infinite recurrance (ie. when neither count nor until is set). If no end_date is set, it will default to DateTime.utc_now().

Event rrule options

Event recurrance details are specified in the rrule. The following options are considered:

  • freq: Represents how frequently the event recurs. Allowed frequencies are DAILY, WEEKLY, and MONTHLY. These can be further modified by the interval option.

  • count (optional): Represents the number of times that an event will recur. This takes precedence over the end_date parameter and the until option.

  • interval (optional): Represents the interval at which events occur. This option works in concert with freq above; by using the interval option, an event could recur every 5 days or every 3 weeks.

  • until (optional): Represents the end date for a recurring event. This takes precedence over the end_date parameter.

  • by_day (optional): Represents the days of the week at which events occur.

The freq option is required for a valid rrule, but the others are optional. They may be used either individually (ex. just freq) or in concert (ex. freq + interval + until).

Future rrule options (not yet supported)

  • byhour (optional): Represents the hours of the day at which events occur.
  • byweekno (optional): Represents the week number at which events occur.
  • bymonthday (optional): Represents the days of the month at which events occur.
  • bymonth (optional): Represents the months at which events occur.
  • byyearday (optional): Represents the days of the year at which events occur.

Examples

iex> dt = Timex.to_date({2016,8,13})
iex> dt_end = Timex.to_date({2016, 8, 23})
iex> event = %ICal.Event{rrule: %ICal.Recurrence{frequency: :daily}, dtstart: dt, dtend: dt}
iex> recurrences =
      ICal.Recurrence.get_recurrences(event)
      |> Enum.to_list()

stream(event, end_date)

@spec stream(
  %ICal.Event{
    alarms: term(),
    attachments: term(),
    attendees: term(),
    categories: term(),
    class: term(),
    comments: term(),
    contacts: term(),
    created: term(),
    custom_properties: term(),
    description: term(),
    dtend: term(),
    dtstamp: term(),
    dtstart: term(),
    duration: term(),
    exdates: term(),
    geo: term(),
    location: term(),
    modified: term(),
    organizer: term(),
    priority: term(),
    rdates: term(),
    recurrence_id: term(),
    related_to: term(),
    request_status: term(),
    resources: term(),
    rrule: term(),
    sequence: term(),
    status: term(),
    summary: term(),
    transparency: term(),
    uid: term(),
    url: term()
  },
  %Date{calendar: term(), day: term(), month: term(), year: term()}
  | %DateTime{
      calendar: term(),
      day: term(),
      hour: term(),
      microsecond: term(),
      minute: term(),
      month: term(),
      second: term(),
      std_offset: term(),
      time_zone: term(),
      utc_offset: term(),
      year: term(),
      zone_abbr: term()
    }
) :: Enumerable.t()