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

Resolve issue related to wrong specs and non counting extra_working_days #34

Open
wants to merge 1 commit into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 15 additions & 15 deletions spec/business/calendar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@
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 @@ -651,7 +651,7 @@
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 @@ -683,7 +683,7 @@
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 @@ -698,7 +698,7 @@
let(:date_1) { "Sat 31/5/2014" }
let(:date_2) { "Sun 8/6/2014" }

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

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

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

it { is_expected.to be(9) }
it { is_expected.to be(10) }
end
end

Expand All @@ -726,7 +726,7 @@
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 +746,9 @@
end

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

it { is_expected.to eq(8) }
it { is_expected.to eq(9) }
end
end
end
Expand Down Expand Up @@ -807,10 +807,10 @@
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 @@ -850,13 +850,13 @@
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" }
let(:date_2) { "Fri 13/6/2014" }

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

Expand Down Expand Up @@ -913,7 +913,7 @@
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