CalendarRecurrence (calendar_recurrence v0.2.0)
View SourceStream of recurring dates.
Options:
start- The start of the recurrencestop- When to stop the recurrence. Defaults to:neverunit- The interval for each recurrence, Defaults to:daystep- The count of how many units to apply for each recurrence. Defaults to1
When the :start is an Elixir DateTime struct with a timezone other than "Etc/UTC" the recurrence will be calculated in that timezone,
so that the wall clock time is stable even when switching between summer and winter time. That means the time will be the same even when
the day has a duration of 23h or 25h.
Examples
iex> recurrence = CalendarRecurrence.new(start: ~D[2018-01-01])
iex> Enum.take(recurrence, 3)
[~D[2018-01-01], ~D[2018-01-02], ~D[2018-01-03]]
iex> recurrence = CalendarRecurrence.new(start: ~N[2018-01-01 12:00:00])
iex> Enum.take(recurrence, 3)
[~N[2018-01-01 12:00:00], ~N[2018-01-02 12:00:00], ~N[2018-01-03 12:00:00]]
iex> recurrence = CalendarRecurrence.new(start: ~U[2018-01-01 12:00:00Z])
iex> Enum.take(recurrence, 3)
[~U[2018-01-01 12:00:00Z], ~U[2018-01-02 12:00:00Z], ~U[2018-01-03 12:00:00Z]]
iex> recurrence = CalendarRecurrence.new(start: ~U[2018-01-01 12:00:00Z], unit: :hour)
iex> Enum.take(recurrence, 3)
[~U[2018-01-01 12:00:00Z], ~U[2018-01-01 13:00:00Z], ~U[2018-01-01 14:00:00Z]]
iex> recurrence = CalendarRecurrence.new(start: ~U[2018-01-01 12:00:00Z], unit: :hour, step: 2)
iex> Enum.take(recurrence, 3)
[~U[2018-01-01 12:00:00Z], ~U[2018-01-01 14:00:00Z], ~U[2018-01-01 16:00:00Z]]
iex> recurrence = CalendarRecurrence.new(start: ~D[2018-01-01], stop: {:count, 3})
iex> Enum.to_list(recurrence)
[~D[2018-01-01], ~D[2018-01-02], ~D[2018-01-03]]
iex> recurrence = CalendarRecurrence.new(start: ~D[2018-01-01], stop: {:until, ~D[2018-01-03]})
iex> Enum.to_list(recurrence)
[~D[2018-01-01], ~D[2018-01-02], ~D[2018-01-03]]
iex> recurrence = CalendarRecurrence.new(start: ~D[2018-01-01], step: fn _ -> 2 end)
iex> Enum.take(recurrence, 3)
[~D[2018-01-01], ~D[2018-01-03], ~D[2018-01-05]]
Summary
Types
@type date() :: Date.t() | NaiveDateTime.t() | DateTime.t() | CalendarRecurrence.T.t()
@type stepper() :: (current :: date() -> pos_integer())
@type t() :: %CalendarRecurrence{ start: date(), step: pos_integer() | stepper(), stop: :never | {:until, date()} | {:count, non_neg_integer()}, unit: unit() }
@type unit() :: :day | :hour | :minute | System.time_unit()