Skip to content

Commit 1d18483

Browse files
dimermanavit
authored andcommitted
fixed parsing of ical with multiple recurrence rules
1 parent 508007e commit 1d18483

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/ice_cube/parsers/ical_parser.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def self.schedule_from_ical(ical_string, options = {})
1616
when 'DURATION'
1717
data[:duration] # FIXME
1818
when 'RRULE'
19-
data[:rrules] = [rule_from_ical(value)]
19+
data[:rrules] ||= []
20+
data[:rrules] += [rule_from_ical(value)]
2021
end
2122
end
2223
Schedule.from_hash data

spec/examples/from_ical_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ module IceCube
102102
RRULE:FREQ=WEEKLY;BYDAY=TH;UNTIL=20130531T100000Z
103103
ICAL
104104

105-
ical_string_woth_multiple_exdates = <<-ICAL.gsub(/^\s*/, '')
105+
ical_string_with_multiple_exdates = <<-ICAL.gsub(/^\s*/, '')
106106
DTSTART;TZID=America/Denver:20130731T143000
107107
DTEND;TZID=America/Denver:20130731T153000
108108
RRULE:FREQ=WEEKLY;UNTIL=20140730T203000Z;BYDAY=MO,WE,FR
@@ -111,6 +111,11 @@ module IceCube
111111
EXDATE;TZID=America/Denver:20130807T143000
112112
ICAL
113113

114+
ical_string_with_multiple_rules = <<-ICAL.gsub(/^\s*/, '' )
115+
DTSTART;TZID=CDT:20151005T195541
116+
RRULE:FREQ=WEEKLY;BYDAY=MO,TU
117+
RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=SU;BYDAY=FR
118+
ICAL
114119

115120
def sorted_ical(ical)
116121
ical.split(/\n/).sort.map { |field|
@@ -359,10 +364,17 @@ def sorted_ical(ical)
359364
end
360365

361366
it 'handles multiple EXDATE lines' do
362-
schedule = IceCube::Schedule.from_ical ical_string_woth_multiple_exdates
367+
schedule = IceCube::Schedule.from_ical ical_string_with_multiple_exdates
363368
schedule.exception_times.count.should == 3
364369
end
365370
end
371+
372+
describe 'multiple rules' do
373+
it 'handles multiple recurrence rules' do
374+
schedule = IceCube::Schedule.from_ical ical_string_with_multiple_rules
375+
schedule.recurrence_rules.count.should == 2
376+
end
377+
end
366378
end
367379

368380
end

0 commit comments

Comments
 (0)