Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions lib/ical/recurrence.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ defmodule ICal.Recurrence do

## Examples

iex> dt = Timex.to_date({2016,8,13})
iex> dt_end = Timex.to_date({2016, 8, 23})
iex> dt = ~D[2016-08-13]
iex> dt_end = ~D[2016-08-23]
iex> event = %ICal.Event{rrule: %ICal.Recurrence{frequency: :daily}, dtstart: dt, dtend: dt}
iex> recurrences =
ICal.Recurrence.stream(event)
Expand Down Expand Up @@ -172,10 +172,10 @@ defmodule ICal.Recurrence do

defp resolve_end_date(%DateTime{} = end_date, %Date{}), do: DateTime.to_date(end_date)

defp shift_opts(:daily, interval), do: [days: interval]
defp shift_opts(:weekly, interval), do: [days: interval * 7]
defp shift_opts(:monthly, interval), do: [months: interval]
defp shift_opts(:yearly, interval), do: [years: interval]
defp shift_opts(:daily, interval), do: [day: interval]
defp shift_opts(:weekly, interval), do: [week: interval]
Comment thread
matthewlehner marked this conversation as resolved.
defp shift_opts(:monthly, interval), do: [month: interval]
defp shift_opts(:yearly, interval), do: [year: interval]

defp add_recurrences_until(original_event, references, until, shift_opts) do
Stream.resource(
Expand Down Expand Up @@ -277,15 +277,8 @@ defmodule ICal.Recurrence do
})
end

defp shift_date(date, shift_opts) do
case Timex.shift(date, shift_opts) do
%Timex.AmbiguousDateTime{} = new_date ->
new_date.after

new_date ->
new_date
end
end
defp shift_date(%Date{} = date, shift_opts), do: Date.shift(date, shift_opts)
defp shift_date(%DateTime{} = date, shift_opts), do: DateTime.shift(date, shift_opts)

defp build_references_by_x_rules(by_x_rrules, component) when by_x_rrules == %{} do
[component]
Expand Down Expand Up @@ -323,8 +316,8 @@ defmodule ICal.Recurrence do
|> Enum.map(fn {_offset, by_day} ->
# TODO: support offsets other than the trivial case of 0
# determine the difference between the by_day and dtstart
day_offset_for_reference = Map.get(day_values, by_day) - Timex.weekday(component.dtstart)
shift(component, days: day_offset_for_reference)
day_offset_for_reference = Map.get(day_values, by_day) - Date.day_of_week(component.dtstart)
shift(component, day: day_offset_for_reference)
end)
end

Expand Down
Loading