aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTeddy Wing2017-05-24 10:49:49 +0200
committerRobert2017-05-29 08:49:52 +0200
commit31c4acfa6a3f9893e99805c5fc1d03fd3392d778 (patch)
tree7f0238ff3c48d65cd5d467a83ef16546e3c49943 /lib
parentc8452bfcedf158abf5c10a0ca8d1449650710eca (diff)
downloadchouette-core-31c4acfa6a3f9893e99805c5fc1d03fd3392d778.tar.bz2
Create `TimeDuration` module for `#exceeds_gap?` method
Put the `exceeds_gap?` method in a new module called `TimeDuration`. This will allow us to use it from both the `Chouette::VehicleJourneyAtStop` class and from the `IncreasingTimeOrderValidator`. Doing this also allows us to test it independently. Haven't yet rewritten the increasing times validator to take advantage of this new method, but adding it now to ensure we don't get an error calling a non-existent method in `VehicleJourneyAtStop`. I changed the signature of the method to take a duration as its first argument. This allows us to set arbitrary durations to compare against and surfaces the duration when reading code where the method is called. Not sure if that's the best approach here, but it seems to make sense for now. Refs #870
Diffstat (limited to 'lib')
-rw-r--r--lib/time_duration.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/time_duration.rb b/lib/time_duration.rb
new file mode 100644
index 000000000..231fff7b8
--- /dev/null
+++ b/lib/time_duration.rb
@@ -0,0 +1,5 @@
+module TimeDuration
+ def self.exceeds_gap?(duration, earlier, later)
+ (4 * 3600) < ((later - earlier) % (3600 * 24))
+ end
+end