module Holidays
def any_holidays_during_work_week?(date, *options)
def any_holidays_during_work_week?(date, *options) monday = date - (date.wday - 1) friday = date + (5 - date.wday) holidays = between(monday, friday, *options) holidays && holidays.count > 0 end
def available_regions
def available_regions Holidays::REGIONS end
def between(start_date, end_date, *options)
def between(start_date, end_date, *options) raise ArgumentError unless start_date && end_date # remove the timezone start_date = start_date.new_offset(0) + start_date.offset if start_date.respond_to?(:new_offset) end_date = end_date.new_offset(0) + end_date.offset if end_date.respond_to?(:new_offset) start_date, end_date = get_date(start_date), get_date(end_date) raise ArgumentError if end_date < start_date if cached_holidays = Factory::Definition.cache_repository.find(start_date, end_date, options) return cached_holidays end Factory::Finder.between.call(start_date, end_date, options) end
def cache_between(start_date, end_date, *options)
def cache_between(start_date, end_date, *options) start_date, end_date = get_date(start_date), get_date(end_date) cache_data = between(start_date, end_date, *options) Factory::Definition.cache_repository.cache_between(start_date, end_date, cache_data, options) end
def get_date(date)
def get_date(date) if date.respond_to?(:to_date) date.to_date else Date.civil(date.year, date.mon, date.mday) end end
def load_all
def load_all path = FULL_DEFINITIONS_PATH + "/" Dir.foreach(path) do |item| next if item == '.' or item == '..' target = path+item next if File.extname(target) != '.rb' require target end end
def load_custom(*files)
def load_custom(*files) regions, rules_by_month, custom_methods, _ = Factory::Definition.file_parser.parse_definition_files(files) custom_methods.each do |method_key, method_entity| custom_methods[method_key] = Factory::Definition.custom_method_proc_decorator.call(method_entity) end Factory::Definition.merger.call(regions, rules_by_month, custom_methods) rules_by_month end
def next_holidays(holidays_count, options, from_date = Date.today)
major version bump we should take the opportunity to change this
FIXME All other methods start with a date and require a date. For the next
def next_holidays(holidays_count, options, from_date = Date.today) raise ArgumentError unless holidays_count raise ArgumentError if options.empty? raise ArgumentError unless options.is_a?(Array) # remove the timezone from_date = from_date.new_offset(0) + from_date.offset if from_date.respond_to?(:new_offset) from_date = get_date(from_date) Factory::Finder.next_holiday.call(holidays_count, from_date, options) end
def on(date, *options)
def on(date, *options) between(date, date, *options) end
def year_holidays(options, from_date = Date.today)
major version bump we should take the opportunity to change this
FIXME All other methods start with a date and require a date. For the next
def year_holidays(options, from_date = Date.today) raise ArgumentError if options.empty? raise ArgumentError unless options.is_a?(Array) # remove the timezone from_date = from_date.new_offset(0) + from_date.offset if from_date.respond_to?(:new_offset) from_date = get_date(from_date) Factory::Finder.year_holiday.call(from_date, options) end