lpil / icalendar

🗓️ A small library for reading and writing ICalendar files.
MIT License
103 stars 56 forks source link

`Recurrence.get_recurrences/2` returns invalid dates after passing leap day once in the recurrence stream #58

Open maciektr opened 3 years ago

maciektr commented 3 years ago

Consider following example

%ICalendar.Event{dtstart: ~U[2020-12-30 01:01:01Z], rrule: %{freq: "MONTHLY"}}
|> ICalendar.Recurrence.get_recurrences(~U[2022-01-01 01:01:01Z])

The first recurrence is 2021-01-30 Then, as there is no 30th day in February, Timex.shift returns 2021-02-28 (as describe in docs) All recurrences returned from stream after that point to 28th day of a month (for instance, the third one is 2021-03-28), which I believe is invalid.

To reproduce run:

ICalendar.Recurrence.get_recurrences(
      %ICalendar.Event{dtstart: ~U[2020-12-30 01:01:01Z], rrule: %{freq: "MONTHLY"}},
      ~U[3000-01-01 01:01:01Z]
    )
    |> Enum.take(3)
    |> IO.inspect()