diff options
Diffstat (limited to 'app/models')
| -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 |
