recurring_events v0.1.0 RecurringEvents

RecurringEvents is an Elixir library providing recurring events support (duh!).

It loosely follows iCal Recurrence rule specification RFC 2445.

Currently, it is ignoring time but if DateTime or NaiveDateTime structure is used time will be preserved (see below).

iex> RecurringEvents.take(~D[2016-12-07], %{freq: :daily}, 3)
[~D[2016-12-07], ~D[2016-12-08], ~D[2016-12-09]]

iex> RecurringEvents.take(~N[2016-01-17 12:21:06], %{freq: :weekly}, 2)
[~N[2016-01-17 12:21:06], ~N[2016-01-24 12:21:06]]

Currently supported rules

  • :count - how many occurences should be return
  • :interval - how often recurrence rule repeats
  • :freq - this is the only required rule, possible values: :yearly, :monthly, :weekly, :daily
  • :by_month - month number or list of month numbers
  • :by_day - day or list of days, possible values: :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday
  • :week_start - start day of the week, see :by_day for possible values

For more usage examples, please, refer to tests

Summary

Functions

Returns list of recurring events based on date and rules

Returns stream of recurring events based on date and rules

Functions

take(date, rules, count)

Returns list of recurring events based on date and rules

Example

iex> RecurringEvents.take(~D[2015-09-13], %{freq: :monthly}, 4)
[~D[2015-09-13], ~D[2015-10-13], ~D[2015-11-13], ~D[2015-12-13]]
unfold(date, rules)

Returns stream of recurring events based on date and rules

Example

iex> RecurringEvents.unfold(~D[2014-06-07], %{freq: :yearly})
...> |> Enum.take(3)
[~D[2014-06-07], ~D[2015-06-07], ~D[2016-06-07]]