Skip to content

Instantly share code, notes, and snippets.

@danreedy
Created June 28, 2011 03:38
Show Gist options
  • Save danreedy/1050439 to your computer and use it in GitHub Desktop.
Save danreedy/1050439 to your computer and use it in GitHub Desktop.
A monkey patch to check for the next business day in X number of days.
class Time
def in_business_days(number_of_days)
result = self.in number_of_days.days
while [0,6].include?(result.wday) || result.to_date.holiday?(:us)
result += 1.day
end
result
end
end
require 'spec_helper'
describe Time do
describe "#in_business_days" do
it "should return June 30 for 3 business days from June 27 " do
actual = Time.parse("2011-06-27").in_business_days 3
actual.should == Time.parse("2011-06-30")
end
it "should return June 27 for 3 business days from June 22" do
actual = Time.parse("2011-06-22").in_business_days 3
actual.should == Time.parse("2011-06-27")
end
it "should return July 5 for 3 business days from June 29 (accounting for July 4 holiday)" do
actual = Time.parse("2011-06-29").in_business_days 3
actual.should == Time.parse("2011-07-05")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment