diff options
| author | Alban Peignier | 2018-04-25 22:46:57 +0200 | 
|---|---|---|
| committer | GitHub | 2018-04-25 22:46:57 +0200 | 
| commit | 7a3d1fb00d3288f776b006fe613b6365e931bd18 (patch) | |
| tree | 20ddf5ff40a133ffc6205e32ea642fcaba838f30 | |
| parent | b930761de0a269c45876b2242e085e23070f8325 (diff) | |
| parent | e15d1e4c59ddeff10a4630fee280618818a67b36 (diff) | |
| download | chouette-core-7a3d1fb00d3288f776b006fe613b6365e931bd18.tar.bz2 | |
Merge pull request #523 from af83/6683-uniformize-timezone-formats
Uniformize the time_zones notation. Refs #6683 
| -rw-r--r-- | app/inputs/full_time_zone_input.rb | 24 | ||||
| -rw-r--r-- | app/views/companies/_form.html.slim | 2 | ||||
| -rw-r--r-- | app/views/referential_companies/_form.html.slim | 2 | ||||
| -rw-r--r-- | app/views/referential_stop_areas/_form.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.slim | 1 | ||||
| -rw-r--r-- | db/migrate/20180425133154_fix_timezones.rb | 19 | 
7 files changed, 48 insertions, 4 deletions
| diff --git a/app/inputs/full_time_zone_input.rb b/app/inputs/full_time_zone_input.rb new file mode 100644 index 000000000..f5d8a9ba2 --- /dev/null +++ b/app/inputs/full_time_zone_input.rb @@ -0,0 +1,24 @@ +class FullTimeZoneInput < SimpleForm::Inputs::CollectionSelectInput +  def collection +    @collection ||= begin +      collection = options.delete(:collection) || ActiveSupport::TimeZone::MAPPING +      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 ||= ->(tz) do +      tz = ActiveSupport::TimeZone[tz.last] +      "(#{tz.formatted_offset}) #{tz.name}" +    end +    value ||= :last + +    [label, value] +  end + +  def input(wrapper_options = {}) +    super wrapper_options +  end +end diff --git a/app/views/companies/_form.html.slim b/app/views/companies/_form.html.slim index ec003b836..4aa08e267 100644 --- a/app/views/companies/_form.html.slim +++ b/app/views/companies/_form.html.slim @@ -9,7 +9,7 @@        = f.input :phone        = f.input :fax        = f.input :email, as: :email -      = f.input :time_zone, include_blank: true +      = f.input :time_zone, as: :full_time_zone, include_blank: true        = f.input :url        = f.input :registration_number, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.registration_number")}        - if resource.custom_fields.present? diff --git a/app/views/referential_companies/_form.html.slim b/app/views/referential_companies/_form.html.slim index 0e7b20af4..bac6d6694 100644 --- a/app/views/referential_companies/_form.html.slim +++ b/app/views/referential_companies/_form.html.slim @@ -9,7 +9,7 @@        = f.input :phone        = f.input :fax        = f.input :email, as: :email -      = f.input :time_zone, include_blank: true +      = f.input :time_zone, as: :full_time_zone, include_blank: true        = f.input :url        = f.input :registration_number, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.registration_number")}        - if resource.custom_fields(@referential.workgroup).any? diff --git a/app/views/referential_stop_areas/_form.html.slim b/app/views/referential_stop_areas/_form.html.slim index 3921c8bf1..bf416ebb0 100644 --- a/app/views/referential_stop_areas/_form.html.slim +++ b/app/views/referential_stop_areas/_form.html.slim @@ -30,7 +30,7 @@        = form.input :fare_code, as: :number        = form.input :nearest_topic_name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.nearest_topic_name")}        = form.input :comment, as: :text, :input_html => { :rows => 5, :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.comment") } -      = form.input :time_zone, :include_blank => true +      = form.input :time_zone, as: :full_time_zone, :include_blank => true        = form.input :url    .pmr_info diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index 220097a69..2ac316632 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -52,7 +52,7 @@            = f.input :fare_code            = f.input :nearest_topic_name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.nearest_topic_name")}            = f.input :comment, as: :text, :input_html => {:rows => 5, :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.comment")} -          = f.input :time_zone, :include_blank => true +          = f.input :time_zone, as: :full_time_zone, include_blank: true            = f.input :url          .pmr_info diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index c4d06f61d..c10d22bfb 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -20,6 +20,7 @@              Chouette::StopArea.tmf('zip_code') => @stop_area.zip_code,              Chouette::StopArea.tmf('city_name') => @stop_area.city_name,              Chouette::StopArea.tmf('country_code') => @stop_area.country_code.presence || '-', +            Chouette::StopArea.tmf('time_zone') => @stop_area.time_zone.presence || '-',              Chouette::StopArea.tmf('status') => stop_area_status(@stop_area),              Chouette::StopArea.tmf('comment') => @stop_area.try(:comment),              }) diff --git a/db/migrate/20180425133154_fix_timezones.rb b/db/migrate/20180425133154_fix_timezones.rb new file mode 100644 index 000000000..0c854c251 --- /dev/null +++ b/db/migrate/20180425133154_fix_timezones.rb @@ -0,0 +1,19 @@ +class FixTimezones < ActiveRecord::Migration +  def convert tz +    return unless tz.present? +    return tz unless ActiveSupport::TimeZone[tz].present? +    ActiveSupport::TimeZone[tz].tzinfo.name +  end + +  def change +    if Apartment::Tenant.current == "public" +      Chouette::StopArea.where.not("time_zone LIKE '%/%'").find_each do |s| +        s.update_column :time_zone, convert(s.time_zone) +      end + +      Chouette::Company.where.not("time_zone LIKE '%/%'").find_each do |c| +        c.update_column :time_zone, convert(c.time_zone) +      end +    end +  end +end | 
