recurrencex v0.2.1 Recurrencex View Source
Simple date recurrences
Link to this section Summary
Functions
A function that finds the date of the next occurence after 'date' with recurrence 'recurrencex'
Link to this section Types
Specs
Link to this section Functions
Specs
next( %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() }, %Recurrencex{frequency: term(), repeat_on: term(), type: 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() }
A function that finds the date of the next occurence after 'date' with recurrence 'recurrencex'
Examples
iex> date = Timex.to_datetime({{2018, 4, 20}, {0, 0, 0}}, "America/Toronto")
...> # repeat every 7 days
...> next = Recurrencex.next(date, %Recurrencex{type: :daily, frequency: 7, repeat_on: []})
...> next == Timex.to_datetime({{2018, 4, 27}, {0, 0, 0}}, "America/Toronto")
true
iex> date = Timex.to_datetime({{2018, 4, 20}, {0, 0, 0}}, "America/Toronto")
...> # repeat on Mondays, Wednesdays, Fridays every week
...> recurrencex = %Recurrencex{type: :weekly, frequency: 1, repeat_on: [1, 3, 5]}
...> next = Recurrencex.next(date, recurrencex)
...> # date was a Friday the 20th, the next recurrence would be Monday the 23rd
...> next == Timex.to_datetime({{2018, 4, 23}, {0, 0, 0}}, "America/Toronto")
true
iex> date = Timex.to_datetime({{2018, 4, 20}, {0, 0, 0}}, "America/Toronto")
...> # repeat on the 20th and 25th of every month
...> recurrencex = %Recurrencex{type: :monthly_day, frequency: 1, repeat_on: [20, 25]}
...> next = Recurrencex.next(date, recurrencex)
...> next == Timex.to_datetime({{2018, 4, 25}, {0, 0, 0}}, "America/Toronto")
true
iex> date = Timex.to_datetime({{2018, 4, 20}, {0, 0, 0}}, "America/Toronto")
...> # repeat on the first Thursday of every month
...> recurrencex = %Recurrencex{type: :monthly_dow, frequency: 1, repeat_on: [{4,1}]}
...> next = Recurrencex.next(date, recurrencex)
...> next == Timex.to_datetime({{2018, 5, 3}, {0, 0, 0}}, "America/Toronto")
true
iex> r = %Recurrencex{type: :monthly_day, frequency: 12, repeat_on: [20]}
...> next = Timex.to_datetime({{2018, 4, 20}, {0, 0, 0}}, "America/Toronto")
...> |> Recurrencex.next(r)
...> |> Recurrencex.next(r)
...> next == Timex.to_datetime({{2020, 4, 20}, {0, 0, 0}}, "America/Toronto")
true