Skip to content

Commit

Permalink
Merge pull request #138 from gocardless/refactor-add
Browse files Browse the repository at this point in the history
Refactor `add_business_days` and `subtract_business_days`
  • Loading branch information
JoeSouthan authored Mar 31, 2023
2 parents f2f9dc1 + cb8ebb3 commit 4c9ccff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
tests:
strategy:
matrix:
ruby-version: [2.6, 2.7, "3.0", 3.1, 3.2]
ruby-version: ["2.6", "2.7", "3.0", "3.1", "3.2"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
10 changes: 2 additions & 8 deletions lib/business/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ def previous_business_day(date)
def add_business_days(date, delta)
date = roll_forward(date)
delta.times do
loop do
date += day_interval_for(date)
break date if business_day?(date)
end
date = next_business_day(date)
end
date
end
Expand All @@ -145,10 +142,7 @@ def add_business_days(date, delta)
def subtract_business_days(date, delta)
date = roll_backward(date)
delta.times do
loop do
date -= day_interval_for(date)
break date if business_day?(date)
end
date = previous_business_day(date)
end
date
end
Expand Down

0 comments on commit 4c9ccff

Please sign in to comment.