Hi,
I鈥檝e got a problem with splitting up my below stated method into two. I鈥檓 on Ruby 2.3.1 using the Holidays Gem, but I think this is probably more related to me not spotting the obvious
The following implementation works correctly, producing 21 business days for December 2016 (in Germany), for instance:
路路路
~~~
require 'date'
require 'holidays'
class DateOperations
聽聽def self.number_of_business_days_between(start_date, end_date)
聽聽聽聽week_days = week_days_between(start_date, end_date)
聽聽聽聽business_days = []
聽聽聽聽week_days.each do |b|
聽聽聽聽聽聽business_days << b unless holiday?(b)
聽聽聽聽end
聽聽聽聽business_days.length
聽聽end
聽聽def self.week_days_between(start_date, end_date)
聽聽聽聽week_day_nbrs = (1..5)
聽聽聽聽(start_date..end_date).select { |w| week_day_nbrs.include?(w.wday) }
聽聽end
聽聽def self.holiday?(date)
聽聽聽聽return false if Holidays.on(date, :de, :informal).empty?
聽聽聽聽true
聽聽end
end
~~~
When delegating gathering of the array with the business days to another method, everything else staying the same, number_of_business_days_between results in 22 for December 2016 in Germany instead of 21:
~~~
聽聽def self.number_of_business_days_between(start_date, end_date)
聽聽聽聽business_days = business_days_between(start_date, end_date)
聽聽聽聽business_days.length
聽聽end
聽聽def self.business_days_between(start_date, end_date)
聽聽聽聽week_days = week_days_between(start_date, end_date)
聽聽聽聽business_days = []
聽聽聽聽week_days.each do |b|
聽聽聽聽聽聽business_days << b unless holiday?(b)
聽聽聽聽end
聽聽end
~~~
From my point of view both implementations of number_of_business_days_between should work exactly the same, unfortunately not for me - any ideas on this?
Many thanks!
Cheers,
Michael