From 2054218dab2a94c2e8002902a98078b272b7a3d0 Mon Sep 17 00:00:00 2001 From: "anatoli.liotych" Date: Thu, 3 Jan 2019 22:20:55 +0300 Subject: [PATCH] Resolve issue related to wrong specs and non counting extra_working_days --- lib/business/calendar.rb | 7 ++++++ spec/business/calendar_spec.rb | 41 +++++++++++++--------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/lib/business/calendar.rb b/lib/business/calendar.rb index bba6989..71b8d2b 100644 --- a/lib/business/calendar.rb +++ b/lib/business/calendar.rb @@ -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) } diff --git a/spec/business/calendar_spec.rb b/spec/business/calendar_spec.rb index 2b7fa6b..f5823e4 100644 --- a/spec/business/calendar_spec.rb +++ b/spec/business/calendar_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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