aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-05-24 11:52:42 +0200
committerRobert2017-05-29 08:49:52 +0200
commit70381d55a7717c0a0d8b8333f6388e20facb9870 (patch)
treef9f3c947b39891321a744cfc1d990d83ed172d8d
parent8efdf7cadf0659601bb303a4eaeb9a5d7f6a78fc (diff)
downloadchouette-core-70381d55a7717c0a0d8b8333f6388e20facb9870.tar.bz2
IncreasingTimeOrderValidator: Use `TimeDuration` `exceeds_gap?` method
Get rid of the `.exceeds_gap?` method in this class and standardise on the one that lives in `TimeDuration`. That one takes a duration, so we pass one in when calling the method. (The method is currently set to use a 4 hour duration. We're just reproducing the existing functionality.) Refs #870
-rw-r--r--app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb b/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb
index a08ca42ea..1380e48b6 100644
--- a/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb
+++ b/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb
@@ -27,22 +27,25 @@ module Chouette
valid = true
return valid unless previous_at_stop
- if self.exceeds_gap?(previous_at_stop.departure_time, at_stop.departure_time)
+ if TimeDuration.exceeds_gap?(
+ 4.hours,
+ previous_at_stop.departure_time,
+ at_stop.departure_time
+ )
valid = false
at_stop.errors.add(:departure_time, 'departure time gap overflow')
end
- if self.exceeds_gap?(previous_at_stop.arrival_time, at_stop.arrival_time)
+ if TimeDuration.exceeds_gap?(
+ 4.hours,
+ previous_at_stop.arrival_time,
+ at_stop.arrival_time
+ )
valid = false
at_stop.errors.add(:arrival_time, 'arrival time gap overflow')
end
valid
end
-
- # TODO: Get rid of this and change to TimeDuration version
- def self.exceeds_gap?(earlier, later)
- (4 * 3600) < ((later - earlier) % (3600 * 24))
- end
end
end