Skip to content

Commit

Permalink
Merge pull request #411 from seejohnrun/parse_rdate
Browse files Browse the repository at this point in the history
Parse RDATE lines in iCal parser
  • Loading branch information
seejohnrun authored Aug 15, 2017
2 parents e960cd2 + ff185a6 commit e5e78e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

* [FEATURE] Added support for parsing RDATE from iCal format

## 0.16.2 / 2017-07-10

* [BUGFIX] Fix serialization of Date values (for `until`) (#399)
Expand Down
11 changes: 7 additions & 4 deletions lib/ice_cube/parsers/ical_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ def self.schedule_from_ical(ical_string, options = {})
(property, tzid) = property.split(';')
case property
when 'DTSTART'
data[:start_time] = Time.parse(value)
data[:start_time] = TimeUtil.deserialize_time(value)
when 'DTEND'
data[:end_time] = Time.parse(value)
data[:end_time] = TimeUtil.deserialize_time(value)
when 'RDATE'
data[:rtimes] ||= []
data[:rtimes] += value.split(',').map { |v| TimeUtil.deserialize_time(v) }
when 'EXDATE'
data[:extimes] ||= []
data[:extimes] += value.split(',').map{|v| Time.parse(v)}
data[:extimes] += value.split(',').map { |v| TimeUtil.deserialize_time(v) }
when 'DURATION'
data[:duration] # FIXME
when 'RRULE'
Expand Down Expand Up @@ -41,7 +44,7 @@ def self.rule_from_ical(ical)
when 'COUNT'
params[:count] = value.to_i
when 'UNTIL'
params[:until] = Time.parse(value).utc
params[:until] = TimeUtil.deserialize_time(value).utc
when 'WKST'
params[:week_start] = TimeUtil.ical_day_to_symbol(value)
when 'BYSECOND'
Expand Down
12 changes: 8 additions & 4 deletions spec/examples/from_ical_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ module IceCube
RRULE:FREQ=WEEKLY;BYDAY=TH;UNTIL=20130531T100000Z
ICAL

ical_string_with_multiple_exdates = <<-ICAL.gsub(/^\s*/, '')
ical_string_with_multiple_exdates_and_rdates = <<-ICAL.gsub(/^\s*/, '')
DTSTART;TZID=America/Denver:20130731T143000
DTEND;TZID=America/Denver:20130731T153000
RRULE:FREQ=WEEKLY;UNTIL=20140730T203000Z;BYDAY=MO,WE,FR
EXDATE;TZID=America/Denver:20130823T143000
EXDATE;TZID=America/Denver:20130812T143000
EXDATE;TZID=America/Denver:20130807T143000
RDATE;TZID=America/Denver:20150812T143000
RDATE;TZID=America/Denver:20150807T143000
ICAL

ical_string_with_multiple_rules = <<-ICAL.gsub(/^\s*/, '' )
Expand Down Expand Up @@ -352,20 +354,22 @@ def sorted_ical(ical)
end

describe "exceptions" do
it 'handles single EXDATE lines' do
it 'handles single EXDATE lines, single RDATE lines' do
start_time = Time.now

schedule = IceCube::Schedule.new(start_time)
schedule.add_recurrence_rule(IceCube::Rule.daily)
schedule.add_exception_time(Time.now + (IceCube::ONE_DAY * 2))
schedule.add_recurrence_time(Time.now + IceCube::ONE_DAY * 4)

ical = schedule.to_ical
expect(sorted_ical(IceCube::Schedule.from_ical(ical).to_ical)).to eq(sorted_ical(ical))
end

it 'handles multiple EXDATE lines' do
schedule = IceCube::Schedule.from_ical ical_string_with_multiple_exdates
it 'handles multiple EXDATE / RDATE lines' do
schedule = IceCube::Schedule.from_ical ical_string_with_multiple_exdates_and_rdates
expect(schedule.exception_times.count).to eq(3)
expect(schedule.recurrence_times.count).to eq(2)
end

it 'should raise ArgumentError when parsing an invalid rule type' do
Expand Down

0 comments on commit e5e78e9

Please sign in to comment.