Skip to content

Commit

Permalink
Merge pull request #33 from Pyronix/32-handle-rdate-as-specified-in-r…
Browse files Browse the repository at this point in the history
…fc-5545

[#32] Handle RDATE as specified in RFC 5545
  • Loading branch information
rahearn authored Oct 29, 2023
2 parents 6548afb + 4b8f6c8 commit e7605bf
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/icalendar/recurrence/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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

Expand Down
16 changes: 16 additions & 0 deletions spec/lib/recurrence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, "+00:00")
expect(occurrence.end_time).to eq(Time.new 2020, 02, 01, 21, 0, 0, "+00:00")
end
end

context "event repeating yearly" do
let(:event) { example_event :first_of_every_year }

Expand Down
43 changes: 43 additions & 0 deletions spec/support/fixtures/dst_rdate_event.ics
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e7605bf

Please # to comment.