@@ -94,15 +94,22 @@ module IceCube
9494
9595 end
9696
97- describe Schedule , 'from_ical' do
97+ describe Schedule , 'from_ical' , system_time_zone : "America/Chicago" do
9898
9999 ical_string = <<-ICAL . gsub ( /^\s */ , '' )
100100 DTSTART:20130314T201500Z
101101 DTEND:20130314T201545Z
102102 RRULE:FREQ=WEEKLY;BYDAY=TH;UNTIL=20130531T100000Z
103103 ICAL
104104
105- ical_string_woth_multiple_exdates = <<-ICAL . gsub ( /^\s */ , '' )
105+ ical_string_with_time_zones = <<-ICAL . gsub ( /^\s */ , '' )
106+ DTSTART;TZID=America/Denver:20130731T143000
107+ DTEND:20130731T153000
108+ RRULE:FREQ=WEEKLY
109+ EXDATE;TZID=America/Chicago:20130823T143000
110+ ICAL
111+
112+ ical_string_with_multiple_exdates = <<-ICAL . gsub ( /^\s */ , '' )
106113 DTSTART;TZID=America/Denver:20130731T143000
107114 DTEND;TZID=America/Denver:20130731T153000
108115 RRULE:FREQ=WEEKLY;UNTIL=20140730T203000Z;BYDAY=MO,WE,FR
@@ -111,6 +118,11 @@ module IceCube
111118 EXDATE;TZID=America/Denver:20130807T143000
112119 ICAL
113120
121+ ical_string_with_multiple_rules = <<-ICAL . gsub ( /^\s */ , '' )
122+ DTSTART;TZID=America/Denver:20151005T195541
123+ RRULE:FREQ=WEEKLY;BYDAY=MO,TU
124+ RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=SU;BYDAY=FR
125+ ICAL
114126
115127 def sorted_ical ( ical )
116128 ical . split ( /\n / ) . sort . map { |field |
@@ -125,6 +137,43 @@ def sorted_ical(ical)
125137 it "loads an ICAL string" do
126138 expect ( IceCube ::Schedule . from_ical ( ical_string ) ) . to be_a ( IceCube ::Schedule )
127139 end
140+
141+ describe "parsing time zones" do
142+ it "sets the time zone of the start time" do
143+ schedule = IceCube ::Schedule . from_ical ( ical_string_with_time_zones )
144+ expect ( schedule . start_time . time_zone ) . to eq ActiveSupport ::TimeZone . new ( "America/Denver" )
145+ expect ( schedule . start_time . is_a? ( Time ) ) . to be true
146+ expect ( schedule . start_time . is_a? ( ActiveSupport ::TimeWithZone ) ) . to be true
147+ end
148+
149+ it "treats UTC as a Time rather than TimeWithZone" do
150+ schedule = IceCube ::Schedule . from_ical ( ical_string )
151+ expect ( schedule . start_time . utc_offset ) . to eq 0
152+ expect ( schedule . start_time . is_a? ( Time ) ) . to be true
153+ expect ( schedule . start_time . is_a? ( ActiveSupport ::TimeWithZone ) ) . to be false
154+ end
155+
156+ it "uses the system time if a time zone is not explicity provided" do
157+ schedule = IceCube ::Schedule . from_ical ( ical_string_with_time_zones )
158+ expect ( schedule . end_time ) . not_to respond_to :time_zone
159+ end
160+
161+ it "sets the time zone of the exception times" do
162+ schedule = IceCube ::Schedule . from_ical ( ical_string_with_time_zones )
163+ expect ( schedule . exception_times [ 0 ] . time_zone ) . to eq ActiveSupport ::TimeZone . new ( "America/Chicago" )
164+ end
165+
166+ it "adding the offset doesnt also change the time" do
167+ schedule = IceCube ::Schedule . from_ical ( ical_string_with_time_zones )
168+ expect ( schedule . exception_times [ 0 ] . hour ) . to eq 14
169+ end
170+
171+ it "loads the ical DTSTART as output by IceCube to_ical method" do
172+ now = Time . new ( 2016 , 5 , 9 , 12 ) . in_time_zone ( "America/Los_Angeles" )
173+ schedule = IceCube ::Schedule . from_ical ( IceCube ::Schedule . new ( now ) . to_ical )
174+ expect ( schedule . start_time ) . to eq ( now )
175+ end
176+ end
128177 end
129178
130179 describe "daily frequency" do
@@ -235,7 +284,6 @@ def sorted_ical(ical)
235284 describe 'monthly frequency' do
236285 it 'matches simple monthly' do
237286 start_time = Time . now
238-
239287 schedule = IceCube ::Schedule . new ( start_time )
240288 schedule . add_recurrence_rule ( IceCube ::Rule . monthly )
241289
@@ -359,10 +407,17 @@ def sorted_ical(ical)
359407 end
360408
361409 it 'handles multiple EXDATE lines' do
362- schedule = IceCube ::Schedule . from_ical ical_string_woth_multiple_exdates
410+ schedule = IceCube ::Schedule . from_ical ical_string_with_multiple_exdates
363411 schedule . exception_times . count . should == 3
364412 end
365413 end
414+
415+ describe 'multiple rules' do
416+ it 'handles multiple recurrence rules' do
417+ schedule = IceCube ::Schedule . from_ical ical_string_with_multiple_rules
418+ schedule . recurrence_rules . count . should == 2
419+ end
420+ end
366421 end
367422
368423end
0 commit comments