Sha256: b92000b4ac5515c31d5781269318e2147667438eab2026e4af30873da2e6be53

Contents?: true

Size: 645 Bytes

Versions: 4

Compression:

Stored size: 645 Bytes

Contents

module TimeClock
  class Shift

    class EndTimeAfterStartTimeError < ArgumentError; end

    attr_reader :start_time, :end_time

    def initialize(start_time, end_time)
      raise EndTimeAfterStartTimeError unless end_time > start_time
      @start_time, @end_time = start_time.to_time, end_time.to_time
    end

    def overlaps?(shift)
      start_time <= shift.end_time && end_time >= shift.start_time
    end

    def overlapping_seconds(shift)
      [[end_time,shift.end_time].min - [start_time,shift.start_time].max,0].max
    end

    def ==(value)
      start_time == value.start_time && end_time == value.end_time
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
time_clock-0.0.9 lib/time_clock/shift.rb
time_clock-0.0.8 lib/time_clock/shift.rb
time_clock-0.0.5 lib/time_clock/shift.rb
time_clock-0.0.4 lib/time_clock/shift.rb