Created
October 8, 2012 23:38
-
-
Save brntbeer/3855640 to your computer and use it in GitHub Desktop.
Add to Fixnum a method to compute business days from today
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
#!/usr/bin/env ruby | |
class Fixnum < Integer | |
# Counts a given number of business days from today | |
def business_days_from_today | |
d = Date.today | |
day_count = 0 | |
while(day_count <= self) | |
if(d.wday != 6) && (d.wday != 0) #=> Only add to our count if we're not on a weekend | |
day_count+=1 | |
end | |
d = d.next #=> Always move to the next day | |
end | |
d-1 #=> Subtract 1 to get the final date since we always jump one ahead at the end. | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment