class WorkingCalendar

Constants

VERSION

Attributes

not_working_dates[R]
not_working_week_days[R]
working_dates[R]
working_week_days[R]
zone_offset[R]

Public Class Methods

new(zone_offset) click to toggle source
# File lib/working_calendar.rb, line 11
def initialize(zone_offset)
  @zone_offset = Timing::ZoneOffset.parse zone_offset
  @working_week_days = []
  @working_dates = []
  @not_working_week_days = []
  @not_working_dates = []
end

Public Instance Methods

add_not_working_date(date, hours_ranges) click to toggle source
# File lib/working_calendar.rb, line 31
def add_not_working_date(date, hours_ranges)
  not_working_dates << SingleDate.new(date, hours_ranges)
end
add_not_working_week_day(day_name, hours_ranges) click to toggle source
# File lib/working_calendar.rb, line 27
def add_not_working_week_day(day_name, hours_ranges)
  not_working_week_days << WeekDay.new(day_name, hours_ranges)
end
add_working_date(date, hours_ranges) click to toggle source
# File lib/working_calendar.rb, line 23
def add_working_date(date, hours_ranges)
  working_dates << SingleDate.new(date, hours_ranges)
end
add_working_week_day(day_name, hours_ranges) click to toggle source
# File lib/working_calendar.rb, line 19
def add_working_week_day(day_name, hours_ranges)
  working_week_days << WeekDay.new(day_name, hours_ranges)
end
working_at?(time) click to toggle source
# File lib/working_calendar.rb, line 35
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