blob: 6138d17f51de2df163738bddefe08d8ba792ae1d (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 | class FullTimeZoneInput < SimpleForm::Inputs::CollectionSelectInput
  def collection
    @collection ||= begin
      collection = options.delete(:collection) || begin
        coll = {}
        TZInfo::Timezone.all_data_zones.map do |tzinfo|
          # v = ActiveSupport::TimeZone.zones_map[k]
        # coll.sort_by do |v|
        #   "(#{v.formatted_offset}) #{v.name}"
        # end
          next if tzinfo.friendly_identifier =~ /^etc/i
          tz = ActiveSupport::TimeZone.new tzinfo.name#, nil, tzinfo
          coll[[tz.utc_offset, tzinfo.friendly_identifier(true)]] = ["(#{tz.formatted_offset}) #{tzinfo.friendly_identifier(true)}", tz.name]
        end
        coll.sort.map(&:last)
      end
      collection.respond_to?(:call) ? collection.call : collection.to_a
    end
  end
  def detect_collection_methods
    label, value = options.delete(:label_method), options.delete(:value_method)
    label ||= :first
    value ||= :last
    [label, value]
  end
  def input(wrapper_options = {})
    super wrapper_options
  end
end
 |