Skip to content

Commit 259681a

Browse files
committed
Deal with difference between local test environment and Travis. Do not set the UTC in to_ical by default.
1 parent 4edbc92 commit 259681a

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

lib/ice_cube/parsers/ical_parser.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ def self.schedule_from_ical(ical_string, options = {})
55
ical_string.each_line do |line|
66
(property, value) = line.split(':')
77
(property, tzid) = property.split(';')
8-
tz = _tz_from_tzid(tzid)
98
case property
109
when 'DTSTART'
11-
data[:start_time] = Time.parse(value).in_time_zone(tz)
10+
data[:start_time] = _parse_in_tzid(value, tzid)
1211
when 'DTEND'
13-
data[:end_time] = Time.parse(value).in_time_zone(tz)
12+
data[:end_time] = _parse_in_tzid(value, tzid)
1413
when 'EXDATE'
1514
data[:extimes] ||= []
1615
data[:extimes] += value.split(',').map do |v|
17-
Time.parse(value).in_time_zone(tz)
16+
_parse_in_tzid(v, tzid)
1817
end
1918
when 'DURATION'
2019
data[:duration] # FIXME
@@ -25,12 +24,12 @@ def self.schedule_from_ical(ical_string, options = {})
2524
Schedule.from_hash data
2625
end
2726

28-
def self._tz_from_tzid(tzid)
29-
time_zone_name = case tzid
30-
when /TZID=/ then tzid.split("=")[1]
31-
else "UTC"
27+
def self._parse_in_tzid(value, tzid)
28+
t = Time.parse(value)
29+
if tzid
30+
t = t.in_time_zone(ActiveSupport::TimeZone[tzid.split("=")[1]])
3231
end
33-
ActiveSupport::TimeZone[time_zone_name]
32+
t
3433
end
3534

3635
def self.rule_from_ical(ical)

spec/examples/from_ical_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ def sorted_ical(ical)
137137
schedule = IceCube::Schedule.from_ical(ical_string_with_time_zones)
138138
expect(schedule.start_time.time_zone).to eq ActiveSupport::TimeZone.new("America/Denver")
139139
end
140-
it "sets the time zone of the end time to UTC if none provided" do
140+
it "uses the system time if a time zone is not explicity provided" do
141141
schedule = IceCube::Schedule.from_ical(ical_string_with_time_zones)
142-
expect(schedule.end_time.time_zone).to eq ActiveSupport::TimeZone.new("UTC")
142+
expect(schedule.end_time).not_to respond_to :time_zone
143143
end
144144
it "sets the time zone of the exception times" do
145145
schedule = IceCube::Schedule.from_ical(ical_string_with_time_zones)

spec/examples/hourly_rule_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ module IceCube
3939
end
4040

4141
it 'should not skip times in DST end hour' do
42-
schedule = Schedule.new(t0 = Time.local(2013, 11, 3, 0, 0, 0))
42+
tz = ActiveSupport::TimeZone["America/Vancouver"]
43+
schedule = Schedule.new(t0 = tz.local(2013, 11, 3, 0, 0, 0))
4344
schedule.add_recurrence_rule Rule.hourly
4445
expect(schedule.first(4)).to eq [
45-
Time.local(2013, 11, 3, 0, 0, 0), # -0700
46-
Time.local(2013, 11, 3, 1, 0, 0), # -0700
47-
Time.local(2013, 11, 3, 2, 0, 0) - ONE_HOUR, # -0800
48-
Time.local(2013, 11, 3, 2, 0, 0), # -0800
46+
tz.local(2013, 11, 3, 0, 0, 0), # -0700
47+
tz.local(2013, 11, 3, 1, 0, 0), # -0700
48+
tz.local(2013, 11, 3, 2, 0, 0) - ONE_HOUR, # -0800
49+
tz.local(2013, 11, 3, 2, 0, 0), # -0800
4950
]
5051
end
5152

0 commit comments

Comments
 (0)