13
14
15
16
17
18
19
20
21
|
# File 'lib/harvest_time_off.rb', line 13
def dates_between(from, to, holiday_regions:)
raise Error, "end date must not be before start date" if to < from
raise Error, "at least one holiday region is required" if holiday_regions.empty?
holidays = Holidays.between(from, to, *(holiday_regions.map { |region| region.downcase.to_sym } + [:observed])).map { |holiday| holiday[:date] }
(from..to).select { |date| date.workday?(holidays:) }
rescue Holidays::InvalidRegion
raise Error, "invalid holiday region: #{holiday_regions.join(", ")}"
end
|