Skip to content

Instantly share code, notes, and snippets.

@brntbeer
Created October 8, 2012 23:38
Show Gist options
  • Save brntbeer/3855640 to your computer and use it in GitHub Desktop.
Save brntbeer/3855640 to your computer and use it in GitHub Desktop.
Add to Fixnum a method to compute business days from today
#!/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