From f5cb9a5e0063166eb22d79bbf0220cef27b74f46 Mon Sep 17 00:00:00 2001 From: Tim Kein Date: Sun, 27 Mar 2022 04:01:24 +0200 Subject: [PATCH 1/2] [#32] Handle RDATE as specified in RFC 5545 --- lib/icalendar/recurrence/schedule.rb | 8 +++++ spec/lib/recurrence_spec.rb | 16 +++++++++ spec/support/fixtures/dst_rdate_event.ics | 43 +++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 spec/support/fixtures/dst_rdate_event.ics diff --git a/lib/icalendar/recurrence/schedule.rb b/lib/icalendar/recurrence/schedule.rb index 909b29b..52d7771 100644 --- a/lib/icalendar/recurrence/schedule.rb +++ b/lib/icalendar/recurrence/schedule.rb @@ -83,6 +83,14 @@ def ice_cube_schedule end end + event.rdate.each do |extra_date_or_dates| + Array(extra_date_or_dates).each do |extra_date| + # exception times should have the same tz offset as the event start or they'll be ignored as different times + # ignored if ActiveSupport::TimeWithZone is available + schedule.add_recurrence_time(TimeUtil.to_time(extra_date, moment: start_time)) + end + end + schedule end diff --git a/spec/lib/recurrence_spec.rb b/spec/lib/recurrence_spec.rb index b0c3e82..6a80d00 100644 --- a/spec/lib/recurrence_spec.rb +++ b/spec/lib/recurrence_spec.rb @@ -100,6 +100,22 @@ end end + context "event repeating weekly with rdates" do + let(:event) { example_event :dst_rdate } + + it "properly includes specified rdates" do + occurrences = event.occurrences_between(start_time, start_time + 4.months) + extra_day_after_period = Date.new 2020, 02, 01 + occurrence = occurrences.find { |o| o.start_time.to_date == extra_day_after_period } + + expect(occurrences.length).to eq(17) + expect(occurrence).to_not be_nil + + expect(occurrence.start_time).to eq(Time.new 2020, 02, 01, 19, 0, 0, "utc") + expect(occurrence.end_time).to eq(Time.new 2020, 02, 01, 21, 0, 0, "utc") + end + end + context "event repeating yearly" do let(:event) { example_event :first_of_every_year } diff --git a/spec/support/fixtures/dst_rdate_event.ics b/spec/support/fixtures/dst_rdate_event.ics new file mode 100644 index 0000000..3dcd1ab --- /dev/null +++ b/spec/support/fixtures/dst_rdate_event.ics @@ -0,0 +1,43 @@ +BEGIN:VCALENDAR +PRODID:-//Google Inc//Google Calendar 70.9054//EN +VERSION:2.0 +CALSCALE:GREGORIAN +METHOD:PUBLISH +X-WR-CALNAME:Minimal example +X-WR-TIMEZONE:Europe/Berlin +X-WR-CALDESC:Example for #221 +BEGIN:VTIMEZONE +TZID:Europe/Berlin +X-LIC-LOCATION:Europe/Berlin +BEGIN:DAYLIGHT +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +TZNAME:CEST +DTSTART:19700329T020000 +RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU +END:DAYLIGHT +BEGIN:STANDARD +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +TZNAME:CET +DTSTART:19701025T030000 +RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU +END:STANDARD +END:VTIMEZONE +BEGIN:VEVENT +DTSTART;TZID=Europe/Berlin:20191016T100000 +DTEND;TZID=Europe/Berlin:20191016T120000 +RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20200129T225959Z;BYDAY=WE +RDATE;TZID=Europe/Berlin:20200201T200000 +DTSTAMP:20191121T083508Z +UID:01234567890123456789@google.com +CREATED:20191001T090000Z +DESCRIPTION:This repeating event should additionally occur on the specified RDATESs +LAST-MODIFIED:20191001T090000Z +LOCATION:Room 1 +SEQUENCE:1 +STATUS:CONFIRMED +SUMMARY:A repeating event +TRANSP:OPAQUE +END:VEVENT +END:VCALENDAR From 4b8f6c86cbb1b6ad1489cd897c41a4fc157010ba Mon Sep 17 00:00:00 2001 From: Tim Kein Date: Sun, 27 Mar 2022 05:46:58 +0200 Subject: [PATCH 2/2] Conform to ruby 2.4 version of Time.new --- spec/lib/recurrence_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/recurrence_spec.rb b/spec/lib/recurrence_spec.rb index 6a80d00..7b263fe 100644 --- a/spec/lib/recurrence_spec.rb +++ b/spec/lib/recurrence_spec.rb @@ -111,8 +111,8 @@ expect(occurrences.length).to eq(17) expect(occurrence).to_not be_nil - expect(occurrence.start_time).to eq(Time.new 2020, 02, 01, 19, 0, 0, "utc") - expect(occurrence.end_time).to eq(Time.new 2020, 02, 01, 21, 0, 0, "utc") + expect(occurrence.start_time).to eq(Time.new 2020, 02, 01, 19, 0, 0, "+00:00") + expect(occurrence.end_time).to eq(Time.new 2020, 02, 01, 21, 0, 0, "+00:00") end end