How to calculate next and previous business days in Rails?
You may need to calculate business days in the future starting from a Saturday or Sunday. 1 business day after a Monday is the Tuesday, 1 business day from a Sunday should also be Tuesday - the starting weekend day should be ignored. The following achieves this:
class Date
def business_days_future(inc)
date = skip_weekend
inc.times do
date = date + 1
date = date.skip_weekend
end
date
end
# If date is a saturday or sunday, advance to the following monday
def skip_weekend
if wday == 0
self + 1
elsif wday == 6
self + 2
else
self
end
end
end