Created
September 1, 2014 20:33
-
-
Save samir/fe02a7124c2e7add6742 to your computer and use it in GitHub Desktop.
Get next and previous business day
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
module BusinessDay | |
def next_business_day | |
self.skip_weekends self, 1 | |
end | |
def previous_business_day | |
self.skip_weekends self, -1 | |
end | |
protected | |
def skip_weekends(date, inc) | |
date += inc | |
while (date.wday % 7 == 0) or (date.wday % 7 == 6) do | |
date += inc | |
end | |
date | |
end | |
end | |
Date.send :include, BusinessDay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment