Skip to content

Instantly share code, notes, and snippets.

@irgmedeiros
Last active August 29, 2015 13:57
Show Gist options
  • Save irgmedeiros/9747273 to your computer and use it in GitHub Desktop.
Save irgmedeiros/9747273 to your computer and use it in GitHub Desktop.
Finds the date shifted by 'days' workdays. (Accept negative numbers too)
def self.workdays_delta(days)
# Finds the date shifted by 'days' workdays.
current_day = Date.today
weekend = [6, 7]
counter = days.abs
while counter > 0
if days > 0
current_day += 1.day else current_day -= 1.day end
if not weekend.include? current_day.cwday and not Holiday.where(holiday_date: current_day).first
counter -= 1
end
end
current_day
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment