class BankWorkingDay::Base
Attributes
holidays[RW]
Public Class Methods
new(holidays_yml_path='../../../holidays.yml')
click to toggle source
# File lib/bank_working_day.rb, line 12 def initialize(holidays_yml_path='../../../holidays.yml') @holidays ||= Holidays.new(holidays_yml_path) end
Public Instance Methods
deduction_date(year: , month: , day: 27)
click to toggle source
# File lib/bank_working_day.rb, line 41 def deduction_date(year: , month: , day: 27) raise InvalidArgumentError if year.to_i.zero? || month.to_i.zero? date = Date.new(year.to_i, month.to_i, day.to_i) while holiday?(date) date += 1 end date end
end_of_month_without_holiday(date)
click to toggle source
# File lib/bank_working_day.rb, line 16 def end_of_month_without_holiday(date) date.end_of_month.day.downto(1) do |last_day| last_day = Date.new(date.year, date.month, last_day) return last_day unless holiday?(last_day) end end
holiday?(date)
click to toggle source
# File lib/bank_working_day.rb, line 52 def holiday?(date) holidays.holiday?(date) end
working_day_after(date: , offset: )
click to toggle source
# File lib/bank_working_day.rb, line 32 def working_day_after(date: , offset: ) offset.times do |i| date += 1 date += 1 while holiday?(date) end date end
working_day_before(date: , offset: )
click to toggle source
# File lib/bank_working_day.rb, line 23 def working_day_before(date: , offset: ) offset.times do |i| date -= 1 date -= 1 while holiday?(date) end date end