Sha256: 84822fc181288d0bfdf8e99b13692f8e03199a7171677d0bbf25864176e60470

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require 'date'
require 'timing'
require 'multi_require'

MultiRequire.require_relative_pattern 'working_calendar/*'

class WorkingCalendar

  attr_reader :zone_offset, :working_week_days, :working_dates, :not_working_week_days, :not_working_dates

  def initialize(zone_offset)
    @zone_offset = Timing::ZoneOffset.parse zone_offset
    @working_week_days = []
    @working_dates = []
    @not_working_week_days = []
    @not_working_dates = []
  end

  def add_working_week_day(day_name, hours_ranges)
    working_week_days << WeekDay.new(day_name, hours_ranges)
  end

  def add_working_date(date, hours_ranges)
    working_dates << SingleDate.new(date, hours_ranges)
  end

  def add_not_working_week_day(day_name, hours_ranges)
    not_working_week_days << WeekDay.new(day_name, hours_ranges)
  end

  def add_not_working_date(date, hours_ranges)
    not_working_dates << SingleDate.new(date, hours_ranges)
  end

  def working_at?(time)
    time_in_zone = Timing::TimeInZone.new(time).to_zone(zone_offset)

    (working_week_days | working_dates).any? { |e| e.include? time_in_zone } &&
    !(not_working_week_days | not_working_dates).any? { |e| e.include? time_in_zone }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
working_calendar-0.1.1 lib/working_calendar.rb
working_calendar-0.1.0 lib/working_calendar.rb