Quick correction on ical export for one event

This commit is contained in:
echarp 2019-04-30 15:39:54 +02:00
parent 0f80393e6e
commit 02269b38f1

View File

@ -1,12 +1,31 @@
:ruby
# Create a calendar with an event (standard method)
cal = Icalendar::Calendar.new
tzid = @event.region.tzid
tzid = event.region.tzid
use_timezone = true
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
use_timezone = false
end
end
cal.event do |e|
e.uid = "#{@event.id}@#{request.domain}"
if use_timezone
e.dtstamp = Icalendar::Values::DateTime.new @event.decision_time, tzid: tzid
e.uid = "#{event.id}@#{request.domain}"
e.dtstart = Icalendar::Values::DateTime.new @event.start_time, tzid: tzid
e.dtend = Icalendar::Values::DateTime.new @event.end_time, tzid: tzid
else
e.dtstamp = Icalendar::Values::DateTime.new @event.decision_time.localtime
e.dtstart = Icalendar::Values::DateTime.new @event.start_time.localtime
e.dtend = Icalendar::Values::DateTime.new @event.end_time.localtime
end
e.summary = @event.title
e.description = to_markdown @event.description.tr '\'', ''
e.location = @event.full_address