Last active
August 29, 2015 13:57
-
-
Save irgmedeiros/9747273 to your computer and use it in GitHub Desktop.
Finds the date shifted by 'days' workdays. (Accept negative numbers too)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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