Attempt to not use a timezone when it is not recognized
This commit is contained in:
parent
4fb494d393
commit
59031bde86
@ -23,6 +23,7 @@ class Region < ApplicationRecord
|
||||
def tzid
|
||||
country = TZInfo::Country.get region.try(:code) || code
|
||||
if country.present? && country.zone_identifiers.length.positive?
|
||||
# Get arbitrarily the first zone for this country
|
||||
country.zone_identifiers[0]
|
||||
else
|
||||
Time.now.zone
|
||||
|
@ -5,6 +5,7 @@
|
||||
cal = Icalendar::Calendar.new
|
||||
@events.each do |event|
|
||||
tzid = event.region.tzid
|
||||
use_timezone = true
|
||||
if cal.timezones.none? { |t| tzid == t.tzid }
|
||||
# Only add this zone once
|
||||
begin
|
||||
@ -13,14 +14,21 @@
|
||||
cal.add_timezone timezone
|
||||
rescue TZInfo::InvalidTimezoneIdentifier
|
||||
# No need to add this tz
|
||||
use_timezone = false
|
||||
end
|
||||
end
|
||||
|
||||
cal.event do |e|
|
||||
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.uid = "#{event.id}@#{request.domain}"
|
||||
e.summary = event.title
|
||||
e.description = to_markdown event.description.tr '\'', '’'
|
||||
e.location = event.full_address.tr '\'', '’'
|
||||
|
@ -12,6 +12,6 @@ class RegionTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'check other timezone is local timezone' do
|
||||
assert regions(:region_other).tzid == Time.now.zone
|
||||
assert regions(:region_other).tzid == 'CEST'
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user