Cocktail.Schedule.occurrences

You're seeing just the function occurrences, go back to Cocktail.Schedule module for more information.
Link to this function

occurrences(schedule, start_time \\ nil)

View Source

Specs

occurrences(t(), Cocktail.time() | nil) :: Enumerable.t()

Creates a stream of occurrences from the given schedule.

An optional start_time can be supplied to not start at the schedule's start time.

The occurrences that are produced by the stream can be one of several types:

Examples

# using a NaiveDateTime
iex> start_time = ~N[2017-01-01 06:00:00]
...> schedule = start_time |> new() |> add_recurrence_rule(:daily, interval: 2, hours: [10, 14])
...> schedule |> occurrences() |> Enum.take(3)
[~N[2017-01-01 10:00:00],
 ~N[2017-01-01 14:00:00],
 ~N[2017-01-03 10:00:00]]

# using an alternate start time
iex> start_time = ~N[2017-01-01 06:00:00]
...> schedule = start_time |> new() |> add_recurrence_rule(:daily, interval: 2, hours: [10, 14])
...> schedule |> occurrences(~N[2017-10-01 06:00:00]) |> Enum.take(3)
[~N[2017-10-02 10:00:00],
 ~N[2017-10-02 14:00:00],
 ~N[2017-10-04 10:00:00]]

# using a DateTime with a time zone
iex> start_time = Timex.to_datetime(~N[2017-01-02 10:00:00], "America/Los_Angeles")
...> schedule = start_time |> new() |> add_recurrence_rule(:daily)
...> schedule |> occurrences() |> Enum.take(3) |> Enum.map(&Timex.format!(&1, "{ISO:Extended}"))
["2017-01-02T10:00:00-08:00",
 "2017-01-03T10:00:00-08:00",
 "2017-01-04T10:00:00-08:00"]

# using a NaiveDateTime with a duration
iex> start_time = ~N[2017-02-01 12:00:00]
...> schedule = start_time |> new(duration: 3_600) |> add_recurrence_rule(:weekly)
...> schedule |> occurrences() |> Enum.take(3)
[%Cocktail.Span{from: ~N[2017-02-01 12:00:00], until: ~N[2017-02-01 13:00:00]},
 %Cocktail.Span{from: ~N[2017-02-08 12:00:00], until: ~N[2017-02-08 13:00:00]},
 %Cocktail.Span{from: ~N[2017-02-15 12:00:00], until: ~N[2017-02-15 13:00:00]}]