aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-04-25 15:34:57 +0200
committerAlban Peignier2018-04-25 22:44:51 +0200
commit0e64912dd2c299df543ed03e2cd6609bc7d6dec6 (patch)
treee9fa08b24b8c231d4671bfc15a7e3c59ffc66950
parentb930761de0a269c45876b2242e085e23070f8325 (diff)
downloadchouette-core-0e64912dd2c299df543ed03e2cd6609bc7d6dec6.tar.bz2
Refs #6683; Uniformize the time_zones notation
-rw-r--r--app/inputs/full_time_zone_input.rb24
-rw-r--r--app/views/companies/_form.html.slim2
-rw-r--r--app/views/referential_companies/_form.html.slim2
-rw-r--r--app/views/referential_stop_areas/_form.html.slim2
-rw-r--r--app/views/stop_areas/_form.html.slim2
-rw-r--r--db/migrate/20180425133154_fix_timezones.rb19
6 files changed, 47 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/db/migrate/20180425133154_fix_timezones.rb b/db/migrate/20180425133154_fix_timezones.rb
new file mode 100644
index 000000000..0e9e5fcb3
--- /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 time_zone: convert(s.time_zone)
+ end
+
+ Chouette::Company.where.not("time_zone LIKE '%/%'").find_each do |c|
+ c.update time_zone: convert(c.time_zone)
+ end
+ end
+ end
+end