From d768698125f45ac35278c015e5cca99e0861b0d7 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 3 May 2018 09:50:23 +0200 Subject: Refs #6867; Remove duplicated entries in TZ select --- app/inputs/full_time_zone_input.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/inputs/full_time_zone_input.rb b/app/inputs/full_time_zone_input.rb index f5d8a9ba2..b3f43fa19 100644 --- a/app/inputs/full_time_zone_input.rb +++ b/app/inputs/full_time_zone_input.rb @@ -1,7 +1,13 @@ class FullTimeZoneInput < SimpleForm::Inputs::CollectionSelectInput def collection @collection ||= begin - collection = options.delete(:collection) || ActiveSupport::TimeZone::MAPPING + collection = options.delete(:collection) || begin + coll = ActiveSupport::TimeZone::MAPPING.invert + coll.sort_by do |k, v| + tz = ActiveSupport::TimeZone[k] + "(#{tz.formatted_offset}) #{tz.name}" + end + end collection.respond_to?(:call) ? collection.call : collection.to_a end end @@ -10,10 +16,10 @@ class FullTimeZoneInput < SimpleForm::Inputs::CollectionSelectInput label, value = options.delete(:label_method), options.delete(:value_method) label ||= ->(tz) do - tz = ActiveSupport::TimeZone[tz.last] + tz = ActiveSupport::TimeZone[tz.first] "(#{tz.formatted_offset}) #{tz.name}" end - value ||= :last + value ||= :first [label, value] end -- cgit v1.2.3