Skip to content

Commit

Permalink
Alternative time zone lookup using strftime, to complement Rails mapping
Browse files Browse the repository at this point in the history
Co-authored-by: Jankees van Woezik <[email protected]>
  • Loading branch information
epologee and jankeesvw committed Apr 28, 2022
1 parent 957b58e commit b2e0af3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/ice_cube/parsers/ical_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.schedule_from_ical(ical_string, options = {})
ical_string.each_line do |line|
(property, value) = line.split(":")
(property, tzid) = property.split(";")
zone = Time.find_zone(tzid) if tzid.present?
zone = find_zone(tzid) if tzid.present?
case property
when "DTSTART"
value = { time: value, zone: zone } if zone.present?
Expand Down Expand Up @@ -92,5 +92,21 @@ def self.rule_from_ical(ical)

Rule.from_hash(params)
end

private

def self.find_zone(tzid)
(_, zone) = tzid&.split("=")
begin
Time.find_zone!(zone) if zone.present?
rescue ArgumentError
(rails_zone, _tzinfo_id) = ActiveSupport::TimeZone::MAPPING.find do |(k, _)|
candidate = Time.find_zone!(k)
candidate.now.strftime("%Z") == zone
end

Time.find_zone(rails_zone)
end
end
end
end

0 comments on commit b2e0af3

Please sign in to comment.