recurring_events v0.4.0 RecurringEvents View Source

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

It loosely follows iCal Recurrence rule specification RFC 2445.

iex> RecurringEvents.take(%{date_start: ~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]]

Supported rules

  • :date_start - start date can be provided directly in rules map
  • :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, :hourly, :minutely, :secondly
  • :week_start - start day of the week, see :by_day for possible values
  • :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. This rule can also accept tuples with occurrence number when used with :monthly or :yearly frequency (e.g. {3, :monday} for 3rd Monday or {-2, :tuesday} for 2nd to last Tuesday)
  • :by_month_day - month day number or list of month day numbers
  • :by_week_number - number of the week in a year, first week should have at least 4 days, :week_start may affect result of this rule
  • :by_year_day - number of the day in a year 1 is the first -1 is the last
  • :by_hour - hour from 0 to 23
  • :by_minute - minute from 0 to 59
  • :by_second - second from 0 to 59
  • :by_set_position - if present, this indicates the nth occurrence of the date withing frequency period
  • :exclude_date - dates to be excluded from the result
  • :until - limit result up to provided date

For more usage examples, please, refer to tests

Link to this section Summary

Functions

Returns list of recurring events based on rules

Returns list of recurring events based on date and rules

Returns stream of recurring events based on rules

Returns stream of recurring events based on date and rules

Link to this section Functions

Returns list of recurring events based on rules

Example

iex> RecurringEvents.take(%{date_start: ~D[2015-09-13], freq: :monthly}, 4)
[~D[2015-09-13], ~D[2015-10-13], ~D[2015-11-13], ~D[2015-12-13]]
Link to this function take(date, rules, count) View Source

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]]

Returns stream of recurring events based on rules

Example

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

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]]