generating times list with step in elixir
Solution 1:
It’s easier to deal with a range with step. To do this, just convert times to seconds from the midnight, use the range, and then convert it back to time instances.
data
|> Enum.flat_map(fn %{since: since, till: till} ->
[since, till] =
[since, till]
|> Enum.map(&Time.to_seconds_after_midnight/1)
|> Enum.map(&elem(&1, 0))
Enum.map(since..till//900, &Time.from_seconds_after_midnight/1)
end)
|> Enum.sort(Time)
#⇒ [~T[10:30:00], ~T[10:45:00], ~T[11:00:00], ~T[11:15:00], ~T[11:30:00],
# ~T[13:30:00], ~T[13:45:00], ~T[14:00:00], ~T[14:15:00], ~T[14:30:00]]
Please note, that for cases when the slot overlaps midnight, this solution should be extended with a conditional, taking this into account.