Sha256: 5671b54eda605169c02d98863e39b1e28be5dc6acdf4b341d778ff47cc8e6302

Contents?: true

Size: 684 Bytes

Versions: 2

Compression:

Stored size: 684 Bytes

Contents

# frozen_string_literal: true

module Blackcal
  # Time of day range
  class TimeOfDayRange
    # Initialize time of day range
    def initialize(start, finish = nil)
      @start = start || 0
      @finish = finish || 0

      @disallowed_hours = if @finish < @start
                            (@start..23).to_a + (0..@finish).to_a
                          else
                            (@start..@finish).to_a
                          end
    end

    # Returns true if it covers timestamp
    # @return [Boolean]
    def cover?(timestamp)
      hour = timestamp.hour
      # min = timestamp.min # TODO: Support minutes
      @disallowed_hours.include?(hour)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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