Skip to content

Commit

Permalink
Resolve issue related to wrong specs and non counting extra_working_days
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoliliotych committed Oct 26, 2023
1 parent d84e3d0 commit 2054218
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
7 changes: 7 additions & 0 deletions lib/business/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ def business_days_between(date1, date2)
in_range && on_biz_day
end

num_biz_days += extra_working_dates.count do |extra_day|
in_range = full_weeks_range.cover?(extra_day)
# Add holiday if it is marked as extra working day
on_weekend = !working_days.include?(extra_day.strftime('%a').downcase)
in_range && on_weekend
end

remaining_range = (date2 - remaining_days...date2)
# Loop through each day in remaining_range and count if a business day
num_biz_days + remaining_range.count { |a| business_day?(a) }
Expand Down
41 changes: 15 additions & 26 deletions spec/business/calendar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,7 @@
context "including business, weekend, holiday days & business date" do
let(:date_1) { "Wed 28/5/2014" }
let(:date_2) { "Thu 12/6/2014" }

it { is_expected.to eq(11) }
it { is_expected.to eq(12) }
end
end

Expand All @@ -650,8 +649,7 @@
context "including business, weekend days, holidays & working date" do
let(:date_1) { "Wed 25/6/2014" }
let(:date_2) { "Tue 8/7/2014" }

it { is_expected.to eq(8) }
it { is_expected.to eq(9) }
end
end
end
Expand Down Expand Up @@ -682,8 +680,7 @@
context "including business, weekend, holilday days & working date" do
let(:date_1) { "Sat 31/5/2014" }
let(:date_2) { "Fri 13/6/2014" }

it { is_expected.to eq(8) }
it { is_expected.to eq(9) }
end
end

Expand All @@ -697,8 +694,7 @@
context "including business, weekend days & working date" do
let(:date_1) { "Sat 31/5/2014" }
let(:date_2) { "Sun 8/6/2014" }

it { is_expected.to be(5) }
it { is_expected.to eql(6) }
end

context "including business, weekend days, and holidays" do
Expand All @@ -709,9 +705,8 @@

context "including business, weekend, holiday days & working date" do
let(:date_1) { "Sat 31/5/2014" }
let(:date_2) { "Sun 14/6/2014" }

it { is_expected.to be(9) }
let(:date_2) { "Sun 15/6/2014" }
it { is_expected.to eql(10) }
end
end

Expand All @@ -725,8 +720,7 @@
context "including business, weekend days & working date" do
let(:date_1) { "Sat 31/5/2014" }
let(:date_2) { "Thu 12/6/2014" }

it { is_expected.to eq(8) }
it { is_expected.to eq(9) }
end
end

Expand All @@ -746,9 +740,8 @@
end

context "including business, weekend days, holidays & working date" do
let(:date_2) { "Tue 13/6/2014" }

it { is_expected.to eq(8) }
let(:date_2) { "Fri 13/6/2014" }
it { is_expected.to eq(9) }
end
end
end
Expand Down Expand Up @@ -807,10 +800,9 @@
end

context "including business/weekend days, holidays & working date" do
let(:date_1) { "27/5/2014" }
let(:date_1) { "Tue 27/5/2014" }
let(:date_2) { "Thu 12/6/2014" }

it { is_expected.to eq(11) }
it { is_expected.to eq(12) }
end
end

Expand Down Expand Up @@ -849,14 +841,12 @@

context "including working date, working & weekend days" do
let(:date_2) { "Tue 10/6/2014" }

it { is_expected.to eq(6) }
it { is_expected.to eq(7) }
end

context "including working date, working & weekend days & holiday" do
let(:date_2) { "Tue 13/6/2014" }

it { is_expected.to eq(8) }
let(:date_2) { "Fri 13/6/2014" }
it { is_expected.to eq(9) }
end
end

Expand Down Expand Up @@ -912,8 +902,7 @@
context "including working dates, weekend & working days" do
let(:date_1) { "Sat 28/6/2014" }
let(:date_2) { "Sat 5/7/2014" }

it { is_expected.to eq(4) }
it { is_expected.to eq(5) }
end
end
end
Expand Down

0 comments on commit 2054218

Please sign in to comment.