Skip to content
Extraits de code Groupes Projets
Valider 59031bde rédigé par echarp's avatar echarp
Parcourir les fichiers

Attempt to not use a timezone when it is not recognized

parent 4fb494d3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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|
e.dtstamp = Icalendar::Values::DateTime.new event.decision_time, tzid: tzid
if use_timezone
e.dtstamp = Icalendar::Values::DateTime.new event.decision_time, tzid: tzid
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.dtstart = Icalendar::Values::DateTime.new event.start_time, tzid: tzid
e.dtend = Icalendar::Values::DateTime.new event.end_time, tzid: tzid
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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter