aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/time_duration.rb8
-rw-r--r--spec/lib/time_duration_spec.rb14
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/time_duration.rb b/lib/time_duration.rb
index f64c81bdd..12419fdc8 100644
--- a/lib/time_duration.rb
+++ b/lib/time_duration.rb
@@ -9,6 +9,12 @@ module TimeDuration
# Time.now + 2.hours
# )
def self.exceeds_gap?(duration, earlier, later)
- duration < (later - earlier)
+ duration < self.duration_without_24_hour_cycles(later - earlier)
+ end
+
+ private
+
+ def self.duration_without_24_hour_cycles(duration)
+ duration % 24.hours
end
end
diff --git a/spec/lib/time_duration_spec.rb b/spec/lib/time_duration_spec.rb
index 2d63eba76..1cba1f6d5 100644
--- a/spec/lib/time_duration_spec.rb
+++ b/spec/lib/time_duration_spec.rb
@@ -14,6 +14,20 @@ describe TimeDuration do
t2 = Time.now + (4.hours + 1.minutes)
expect(TimeDuration.exceeds_gap?(4.hours, t1, t2)).to be_truthy
end
+
+ it "returns true when `earlier` is later than `later`" do
+ earlier = Time.new(2000, 1, 1, 11, 0, 0, 0)
+ later = Time.new(2000, 1, 1, 12, 0, 0, 0)
+
+ expect(TimeDuration.exceeds_gap?(4.hours, later, earlier)).to be true
+ end
+
+ it "returns false when `earlier` == `later`" do
+ earlier = Time.new(2000, 1, 1, 1, 0, 0, 0)
+ later = earlier
+
+ expect(TimeDuration.exceeds_gap?(4.hours, later, earlier)).to be false
+ end
end
end
end