From 4fb494d393426c47022f32d8dd77c1657270dfdc Mon Sep 17 00:00:00 2001 From: echarp Date: Sat, 27 Apr 2019 15:53:54 +0200 Subject: [PATCH] Only add a timezone once to an ical --- app/views/events/index.ics.haml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/views/events/index.ics.haml b/app/views/events/index.ics.haml index 9fd89dcb..91712c4a 100644 --- a/app/views/events/index.ics.haml +++ b/app/views/events/index.ics.haml @@ -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|