aboutsummaryrefslogtreecommitdiffstats
path: root/lib/time_duration.rb
blob: 12419fdc8a0b69136124b293bb562c4257a35e11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module TimeDuration
  # `earlier` and `later` are times. Get the duration between those times and
  # check whether it's longer than the given `duration`.
  #
  # Example:
  #   TimeDuration.exceeds_gap?(
  #     4.hours,
  #     Time.now,
  #     Time.now + 2.hours
  #   )
  def self.exceeds_gap?(duration, earlier, later)
    duration < self.duration_without_24_hour_cycles(later - earlier)
  end

  private

  def self.duration_without_24_hour_cycles(duration)
    duration % 24.hours
  end
end