Skip to content

Commit 3a4ab88

Browse files
epologeeJankees van Woezik
andcommitted
Alternative time zone lookup using strftime, to complement Rails mapping
Co-authored-by: Jankees van Woezik <[email protected]>
1 parent f1d7f6e commit 3a4ab88

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/ice_cube/parsers/ical_parser.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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-
zone = Time.find_zone(tzid) if tzid.present?
8+
zone = find_zone(tzid) if tzid.present?
99
case property
1010
when "DTSTART"
1111
value = {time: value, zone: zone} if zone.present?
@@ -92,5 +92,18 @@ def self.rule_from_ical(ical)
9292

9393
Rule.from_hash(params)
9494
end
95+
96+
private_class_method def self.find_zone(tzid)
97+
(_, zone) = tzid&.split("=")
98+
begin
99+
Time.find_zone!(zone) if zone.present?
100+
rescue ArgumentError
101+
(rails_zone, _tzinfo_id) = ActiveSupport::TimeZone::MAPPING.find do |(k, _)|
102+
Time.find_zone!(k).now.strftime("%Z") == zone
103+
end
104+
105+
Time.find_zone(rails_zone)
106+
end
107+
end
95108
end
96109
end

0 commit comments

Comments
 (0)