Sha256: 7efc7e3d819d6a7c6458d4fa3a2f912b1c3c9b2e7adefcd6a512ae3ae698622b

Contents?: true

Size: 597 Bytes

Versions: 2

Compression:

Stored size: 597 Bytes

Contents

# frozen_string_literal: true

module Blackcal
  # Time range
  class TimeRange
    attr_reader :start, :finish

    # Initialize time range
    def initialize(start_time, finish_time = nil)
      @start = start_time
      @finish = finish_time
    end

    # Returns true if it covers timestamp
    # @return [Boolean]
    def cover?(timestamp)
      return false if start.nil? && finish.nil?
      return start < timestamp if finish.nil?
      return finish > timestamp if start.nil?

      return true if finish < timestamp
      return true if start > timestamp

      false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blackcal-0.2.0 lib/blackcal/range/time_range.rb
blackcal-0.1.0 lib/blackcal/time_range.rb