business 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7aab6453e38130641098c102e0b05f1d5c40cd957710c80f3b53f4670175ce6
4
- data.tar.gz: 2ae585a9a460e340db0821c755a787795e7504914af8febb247c451beb8f37f2
3
+ metadata.gz: 9f04f06e8df7909e07f17eb5ef5066935eea815e7139260bc1542d785f999d3b
4
+ data.tar.gz: 68df07bcc51b18a1406badfaeeeb78c05412d726a506be589a7bdbd139105877
5
5
  SHA512:
6
- metadata.gz: ffe309242e862845535efb526d3f4ec95852bd685f026c97fdac4bcd4eec88051e47481f5d1354b98a9f34af47dd4858b417fe173b6f9498b52c226a6c491bac
7
- data.tar.gz: 322e9a49e3fcec9078b6c5e1d78eb6ea0d4abc0bc47f95550cbb6069d72715c00d8c5868279bfdfc5e69776e7e85cea03fc3994441522ff7a84abb82411e867f
6
+ metadata.gz: 95d2bf588e43841cc35e48e416d610466a18738a777c812d7c7dff1d121d715d270247e5a2895753c3bc1742400f58e924a626dbe152e0d0ed5a9803241070d4
7
+ data.tar.gz: c7e583aba5f2870a3ddb0ec5e91ef6e64e03dfb5cf5de1a6d246bea345ef9cccb3304dc6d21edb3f5508ae62646b1f7dd8330578a1457b96eaf3bd46fa2a6faa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Upcoming
2
2
 
3
+ ## 3.1.0 - Sept 28, 2026
4
+
5
+ - Fix `business_days_between` not counting extra working dates in full weeks #34 - thanks @anatoliliotych!
6
+
3
7
  # 3.0.0 - Sept 29, 2026
4
8
 
5
9
  - Removed support for Ruby 3.2 and earlier
data/README.md CHANGED
@@ -46,7 +46,7 @@ calendar = Business::Calendar.new(
46
46
 
47
47
  Defining a calendar as a Ruby object may not be convenient, so we provide a way of defining these calendars as YAML. Below we will walk through the necessary [steps](#example-calendar) to build your first calendar. All keys are optional and will default to the following:
48
48
 
49
- Note: Elements of `holidays` and `extra_working_dates` may be either strings that `Date.parse()` [can understand](https://ruby-doc.org/stdlib-2.7.1/libdoc/date/rdoc/Date.html#method-c-parse), or `YYYY-MM-DD` (which is considered as a Date by Ruby YAML itself)[https://github.com/ruby/psych/blob/6ec6e475e8afcf7868b0407fc08014aed886ecf1/lib/psych/scalar_scanner.rb#L60].
49
+ Note: Elements of `holidays` and `extra_working_dates` may be either strings that `Date.parse()` [can understand](https://ruby-doc.org/stdlib-2.7.1/libdoc/date/rdoc/Date.html#method-c-parse), or `YYYY-MM-DD` [which is considered as a Date by Ruby YAML itself](https://github.com/ruby/psych/blob/6ec6e475e8afcf7868b0407fc08014aed886ecf1/lib/psych/scalar_scanner.rb#L60).
50
50
 
51
51
  #### YAML file Structure
52
52
 
@@ -139,6 +139,16 @@ calendar.subtract_business_days(date, 4).strftime("%A, %d %B %Y")
139
139
  # => "Friday, 06 June 2014"
140
140
  ```
141
141
 
142
+ For getting the next or previous business day, instead of passing `1` to `add_business_days` or `subtract_business_days`, `next_business_day` and `previous_business_day` could be used respectively:
143
+
144
+ ```ruby
145
+ date = Date.parse("Friday, 13 June 2014")
146
+ calendar.next_business_day(date).strftime("%A, %d %B %Y")
147
+ # => "Monday, 16 June 2014"
148
+ calendar.previous_business_day(date).strftime("%A, %d %B %Y")
149
+ # => "Thursday, 12 June 2014"
150
+ ```
151
+
142
152
  The `roll_forward` and `roll_backward` methods snap a date to a nearby business day. If provided with a business day, they will return that date. Otherwise, they will advance (forward for `roll_forward` and backward for `roll_backward`) until a business day is found.
143
153
 
144
154
  ```ruby
@@ -194,6 +194,15 @@ module Business
194
194
  in_range && on_biz_day
195
195
  end
196
196
 
197
+ num_biz_days += extra_working_dates.count do |extra_day|
198
+ in_range = full_weeks_range.cover?(extra_day)
199
+ # Only pick an extra working date if it's on a non-working day (e.g., a
200
+ # weekend) and not a holiday, as the setters bypass that validation
201
+ on_non_working_day =
202
+ !working_days.include?(extra_day.strftime("%a").downcase)
203
+ in_range && on_non_working_day && !holiday?(extra_day)
204
+ end
205
+
197
206
  remaining_range = ((date2 - remaining_days)...date2)
198
207
  # Loop through each day in remaining_range and count if a business day
199
208
  num_biz_days + remaining_range.count { |a| business_day?(a) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Business
4
- VERSION = "3.0.0"
4
+ VERSION = "3.1.0"
5
5
  end
@@ -694,7 +694,7 @@ RSpec.describe Business::Calendar do
694
694
  let(:date_1) { "Wed 28/5/2014" }
695
695
  let(:date_2) { "Thu 12/6/2014" }
696
696
 
697
- it { is_expected.to eq(11) }
697
+ it { is_expected.to eq(12) }
698
698
  end
699
699
  end
700
700
 
@@ -717,7 +717,7 @@ RSpec.describe Business::Calendar do
717
717
  let(:date_1) { "Wed 25/6/2014" }
718
718
  let(:date_2) { "Tue 8/7/2014" }
719
719
 
720
- it { is_expected.to eq(8) }
720
+ it { is_expected.to eq(9) }
721
721
  end
722
722
  end
723
723
  end
@@ -749,7 +749,7 @@ RSpec.describe Business::Calendar do
749
749
  let(:date_1) { "Sat 31/5/2014" }
750
750
  let(:date_2) { "Fri 13/6/2014" }
751
751
 
752
- it { is_expected.to eq(8) }
752
+ it { is_expected.to eq(9) }
753
753
  end
754
754
  end
755
755
 
@@ -764,7 +764,7 @@ RSpec.describe Business::Calendar do
764
764
  let(:date_1) { "Sat 31/5/2014" }
765
765
  let(:date_2) { "Sun 8/6/2014" }
766
766
 
767
- it { is_expected.to be(5) }
767
+ it { is_expected.to eq(6) }
768
768
  end
769
769
 
770
770
  context "including business, weekend days, and holidays" do
@@ -775,9 +775,9 @@ RSpec.describe Business::Calendar do
775
775
 
776
776
  context "including business, weekend, holiday days & working date" do
777
777
  let(:date_1) { "Sat 31/5/2014" }
778
- let(:date_2) { "Sun 14/6/2014" }
778
+ let(:date_2) { "Sun 15/6/2014" }
779
779
 
780
- it { is_expected.to be(9) }
780
+ it { is_expected.to be(10) }
781
781
  end
782
782
  end
783
783
 
@@ -792,7 +792,7 @@ RSpec.describe Business::Calendar do
792
792
  let(:date_1) { "Sat 31/5/2014" }
793
793
  let(:date_2) { "Thu 12/6/2014" }
794
794
 
795
- it { is_expected.to eq(8) }
795
+ it { is_expected.to eq(9) }
796
796
  end
797
797
  end
798
798
 
@@ -812,9 +812,9 @@ RSpec.describe Business::Calendar do
812
812
  end
813
813
 
814
814
  context "including business, weekend days, holidays & working date" do
815
- let(:date_2) { "Tue 13/6/2014" }
815
+ let(:date_2) { "Fri 13/6/2014" }
816
816
 
817
- it { is_expected.to eq(8) }
817
+ it { is_expected.to eq(9) }
818
818
  end
819
819
  end
820
820
  end
@@ -873,10 +873,10 @@ RSpec.describe Business::Calendar do
873
873
  end
874
874
 
875
875
  context "including business/weekend days, holidays & working date" do
876
- let(:date_1) { "27/5/2014" }
876
+ let(:date_1) { "Tue 27/5/2014" }
877
877
  let(:date_2) { "Thu 12/6/2014" }
878
878
 
879
- it { is_expected.to eq(11) }
879
+ it { is_expected.to eq(12) }
880
880
  end
881
881
  end
882
882
 
@@ -916,13 +916,13 @@ RSpec.describe Business::Calendar do
916
916
  context "including working date, working & weekend days" do
917
917
  let(:date_2) { "Tue 10/6/2014" }
918
918
 
919
- it { is_expected.to eq(6) }
919
+ it { is_expected.to eq(7) }
920
920
  end
921
921
 
922
922
  context "including working date, working & weekend days & holiday" do
923
- let(:date_2) { "Tue 13/6/2014" }
923
+ let(:date_2) { "Fri 13/6/2014" }
924
924
 
925
- it { is_expected.to eq(8) }
925
+ it { is_expected.to eq(9) }
926
926
  end
927
927
  end
928
928
 
@@ -979,7 +979,7 @@ RSpec.describe Business::Calendar do
979
979
  let(:date_1) { "Sat 28/6/2014" }
980
980
  let(:date_2) { "Sat 5/7/2014" }
981
981
 
982
- it { is_expected.to eq(4) }
982
+ it { is_expected.to eq(5) }
983
983
  end
984
984
  end
985
985
  end
@@ -999,6 +999,33 @@ RSpec.describe Business::Calendar do
999
999
  it { is_expected.to eq(4) }
1000
1000
  end
1001
1001
  end
1002
+
1003
+ context "if a calendar has an extra working date" do
1004
+ context "for a range less than a week long" do
1005
+ let(:date_1) { "Fri 30/5/2014" }
1006
+ let(:date_2) { "Tue 3/6/2014" }
1007
+
1008
+ it { is_expected.to eq(3) }
1009
+ end
1010
+
1011
+ context "for a range more than a week long" do
1012
+ let(:date_1) { "Mon 26/5/2014" }
1013
+ let(:date_2) { "Mon 9/6/2014" }
1014
+
1015
+ it { is_expected.to eq(10) }
1016
+ end
1017
+
1018
+ context "set after initialisation on a working day and a holiday" do
1019
+ before do
1020
+ calendar.set_extra_working_dates(["Wed 4/6/2014", "Sun 22/6/2014"])
1021
+ end
1022
+
1023
+ let(:date_1) { "Mon 2/6/2014" }
1024
+ let(:date_2) { "Mon 30/6/2014" }
1025
+
1026
+ it { is_expected.to eq(16) }
1027
+ end
1028
+ end
1002
1029
  end
1003
1030
  end
1004
1031
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCcardless