Only add a timezone once to an ical

This commit is contained in:
echarp 2019-04-27 15:53:54 +02:00
parent e2f9e707c3
commit 4fb494d393

View File

@ -5,12 +5,15 @@
cal = Icalendar::Calendar.new
@events.each do |event|
tzid = event.region.tzid
begin
tz = TZInfo::Timezone.get tzid
timezone = tz.ical_timezone event.start_time
cal.add_timezone timezone
rescue TZInfo::InvalidTimezoneIdentifier
# No need to add this tz
if cal.timezones.none? { |t| tzid == t.tzid }
# Only add this zone once
begin
tz = TZInfo::Timezone.get tzid
timezone = tz.ical_timezone event.start_time
cal.add_timezone timezone
rescue TZInfo::InvalidTimezoneIdentifier
# No need to add this tz
end
end
cal.event do |e|