Skip to content

Instantly share code, notes, and snippets.

@samir
Created September 1, 2014 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samir/fe02a7124c2e7add6742 to your computer and use it in GitHub Desktop.
Save samir/fe02a7124c2e7add6742 to your computer and use it in GitHub Desktop.
Get next and previous business day
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