How to calculate next and previous business days in Rails?
If you are running on rails, You could create a config/initializers/date_time.rb
class DateTime
def next_business_day
# if its a friday saturday or sunday
if self.day > 4
# calculate the remaining days to add to the current day
remaining_days = 7 - self.day + 1
return remaining_days.days.from_now
else
# return tomorrow
return self.tomorrow
end
end
end
usage:
a = DateTime.now
a.next_business_day
=> Mon, 08 Jun 2020 13:46:13 UTC +00:00