Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling infinite range in business_dates_until #222

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/business_time/core_ext/date.rb
Expand Up @@ -7,6 +7,10 @@ def business_days_until(to_date, inclusive = false, options={})
end

def business_dates_until(to_date, inclusive = false, options={})
unless to_date
raise ArgumentError.new("To date must not be nil.")
end

if inclusive
(self..to_date).select{|this_date| this_date.workday?(options)}
else
Expand Down
6 changes: 6 additions & 0 deletions test/test_calculating_business_dates.rb
Expand Up @@ -41,4 +41,10 @@
monday = Date.parse("December 20, 2010")
assert_equal [wednesday, thursday], wednesday.business_dates_until(monday, false, holidays: [free_friday])
end

it "raises ArgumentError if to date is not provided" do
assert_raises ArgumentError do
Date.current.business_dates_until(nil)
end
end
end