diff options
| author | Zog | 2018-01-08 11:06:20 +0100 |
|---|---|---|
| committer | Zog | 2018-01-11 21:55:48 +0100 |
| commit | ef3942099583f86d3f355a1bac8d99ce16cd2de3 (patch) | |
| tree | 0519d8d4d4495da9acc7d0e02e36a2f68028c527 /app/models/chouette | |
| parent | 1fd6d7d0cfb63b024860d1c29fca089432fce2e1 (diff) | |
| download | chouette-core-ef3942099583f86d3f355a1bac8d99ce16cd2de3.tar.bz2 | |
Refs #5493 @1h; Use local time in the Journeys editor
We store UTC times in the database though
Diffstat (limited to 'app/models/chouette')
| -rw-r--r-- | app/models/chouette/stop_area.rb | 6 | ||||
| -rw-r--r-- | app/models/chouette/vehicle_journey.rb | 6 | ||||
| -rw-r--r-- | app/models/chouette/vehicle_journey_at_stop.rb | 30 |
3 files changed, 39 insertions, 3 deletions
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 52602be9f..b16bbb487 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -358,11 +358,17 @@ module Chouette update_attribute :deleted_at, Time.now end + def country_name return unless country_code country = ISO3166::Country[country_code] country.translations[I18n.locale.to_s] || country.name end + + def time_zone_formatted_offset + return nil unless time_zone.present? + ActiveSupport::TimeZone[time_zone].formatted_offset + end end end diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index 1904e1b92..67216e422 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -132,10 +132,14 @@ module Chouette def update_vjas_from_state state state.each do |vjas| next if vjas["dummy"] + stop_point = Chouette::StopPoint.find_by(objectid: vjas['stop_point_objectid']) + stop_area = stop_point&.stop_area + tz = stop_area&.time_zone + tz = tz && ActiveSupport::TimeZone[tz] params = {}.tap do |el| ['arrival_time', 'departure_time'].each do |field| time = "#{vjas[field]['hour']}:#{vjas[field]['minute']}" - el[field.to_sym] = Time.parse("2000-01-01 #{time}:00 UTC") + el[field.to_sym] = Time.parse("2000-01-01 #{time}:00 #{tz&.formatted_offset || "UTC"}") end end stop = create_or_find_vjas_from_state(vjas) diff --git a/app/models/chouette/vehicle_journey_at_stop.rb b/app/models/chouette/vehicle_journey_at_stop.rb index 6b3c1e7de..f1a3cdcaa 100644 --- a/app/models/chouette/vehicle_journey_at_stop.rb +++ b/app/models/chouette/vehicle_journey_at_stop.rb @@ -77,11 +77,37 @@ module Chouette end def departure - departure_time.utc.strftime "%H:%M" if departure_time + format_time departure_time.utc end def arrival - arrival_time.utc.strftime "%H:%M" if arrival_time + format_time arrival_time.utc + end + + def departure_local_time + local_time departure_time + end + + def arrival_local_time + local_time arrival_time + end + + def departure_local + format_time departure_local_time + end + + def arrival_local + format_time arrival_local_time + end + + private + def local_time time + return time unless stop_point&.stop_area&.time_zone.present? + time + ActiveSupport::TimeZone[stop_point.stop_area.time_zone].utc_offset + end + + def format_time time + time.strftime "%H:%M" if time end end |
