business 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31ba206f257f17ef5bdfa3c60e9e81f2e5e2e71436a701513643f90e783d844d
4
- data.tar.gz: bda97edfe037b2f509b4d037d46a39b89c5ed96130872c6e090da461c6783418
3
+ metadata.gz: c1e6ab03fc3769877d942e77c54647175c8b8554e016fb8c2fb491c4596db07d
4
+ data.tar.gz: e76c9f5de45c78dc790866d841da5eb234ea8d308e8ba9c9d292b01eb49cb182
5
5
  SHA512:
6
- metadata.gz: 07576b028c3b7c31fd5be9fc1c1588b31b76b629d6381c73566a828db6add04ee47f7f24091274ef55c0441666551922a35b97ccbb112224fe85d3bf24865dd0
7
- data.tar.gz: 81aae610dd327487aa95b11b04b12d5d909f3296c36a2d49ff9147dc1a2276b4e024fffe2fe5cb8fa072a60b2a667d7b5f0cf207e919e2bc796d6693d01a731a
6
+ metadata.gz: 4c416c3a2845f6ea9b5016d173a8e30b0308a57021c163ad996407e20dae627d5fe10542f30e43fbf4d4e994b4fb99f967c7fb86842eedac89529e81698e5727
7
+ data.tar.gz: 0c163bd5dc87ff5246022b63e472829924ad9c41468287ef811e700d5b52e503278301c02968c0602933bca8d633d176a2ed90a36be332e590712b68ea4d8ea7
@@ -1,3 +1,7 @@
1
+ ## 2.1.0 - June 8, 2020
2
+
3
+ - Add seperate `working_day?` and `holiday?` methods to the calendar
4
+
1
5
  ## 2.0.0 - May 4, 2020
2
6
 
3
7
  🚨 **BREAKING CHANGES** 🚨
data/README.md CHANGED
@@ -131,6 +131,20 @@ calendar.business_day?(Date.parse("Sunday, 8 June 2014"))
131
131
  # => false
132
132
  ```
133
133
 
134
+ More specifically you can check if a given `business_day?` is either a `working_day?` or a `holiday?` using methods on `Business::Calendar`.
135
+
136
+ ```ruby
137
+ # Assuming "Monday, 9 June 2014" is a holiday
138
+ calendar.working_day?(Date.parse("Monday, 9 June 2014"))
139
+ # => true
140
+ calendar.holiday?(Date.parse("Monday, 9 June 2014"))
141
+ # => true
142
+ # Monday is a working day, but we have a holiday so it's not
143
+ # a business day
144
+ calendar.business_day?(Date.parse("Monday, 9 June 2014"))
145
+ # => false
146
+ ```
147
+
134
148
  ## Business day arithmetic
135
149
 
136
150
  The `add_business_days` and `subtract_business_days` are used to perform business day arithmetic on dates.
@@ -57,16 +57,26 @@ module Business
57
57
  set_extra_working_dates(config[:extra_working_dates])
58
58
  set_working_days(config[:working_days])
59
59
  set_holidays(config[:holidays])
60
+
61
+ unless (@holidays & @extra_working_dates).none?
62
+ raise ArgumentError, 'Holidays cannot be extra working dates'
63
+ end
60
64
  end
61
65
 
62
66
  # Return true if the date given is a business day (typically that means a
63
67
  # non-weekend day) and not a holiday.
64
68
  def business_day?(date)
65
69
  date = date.to_date
66
- return true if extra_working_dates.include?(date)
67
- return false unless working_days.include?(date.strftime('%a').downcase)
68
- return false if holidays.include?(date)
69
- true
70
+ working_day?(date) && !holiday?(date)
71
+ end
72
+
73
+ def working_day?(date)
74
+ date = date.to_date
75
+ extra_working_dates.include?(date) || working_days.include?(date.strftime('%a').downcase)
76
+ end
77
+
78
+ def holiday?(date)
79
+ holidays.include?(date.to_date)
70
80
  end
71
81
 
72
82
  # Roll forward to the next business day. If the date given is a business
@@ -191,8 +201,6 @@ module Business
191
201
  # Internal method for assigning holidays from a calendar config.
192
202
  def set_holidays(holidays)
193
203
  @holidays = parse_dates(holidays)
194
- return if (@holidays & @extra_working_dates).none?
195
- raise ArgumentError, 'Holidays cannot be extra working dates'
196
204
  end
197
205
 
198
206
  def set_extra_working_dates(extra_working_dates)
@@ -1,3 +1,3 @@
1
1
  module Business
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -202,6 +202,62 @@ describe Business::Calendar do
202
202
  end
203
203
  end
204
204
 
205
+ describe "#working_day?" do
206
+ let(:calendar) do
207
+ Business::Calendar.new(holidays: ["9am, Tuesday 1st Jan, 2013"],
208
+ extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
209
+ end
210
+ subject { calendar.working_day?(day) }
211
+
212
+ context "when given a working day" do
213
+ let(:day) { date_class.parse("9am, Wednesday 2nd Jan, 2013") }
214
+ it { is_expected.to be_truthy }
215
+ end
216
+
217
+ context "when given a non-working day" do
218
+ let(:day) { date_class.parse("9am, Saturday 5th Jan, 2013") }
219
+ it { is_expected.to be_falsey }
220
+ end
221
+
222
+ context "when given a working day that is a holiday" do
223
+ let(:day) { date_class.parse("9am, Tuesday 1st Jan, 2013") }
224
+ it { is_expected.to be_truthy }
225
+ end
226
+
227
+ context "when given a non-business day that is a working date" do
228
+ let(:day) { date_class.parse("9am, Sunday 6th Jan, 2013") }
229
+ it { is_expected.to be_truthy }
230
+ end
231
+ end
232
+
233
+ describe "#holiday?" do
234
+ let(:calendar) do
235
+ Business::Calendar.new(holidays: ["9am, Tuesday 1st Jan, 2013"],
236
+ extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
237
+ end
238
+ subject { calendar.holiday?(day) }
239
+
240
+ context "when given a working day that is not a holiday" do
241
+ let(:day) { date_class.parse("9am, Wednesday 2nd Jan, 2013") }
242
+ it { is_expected.to be_falsey }
243
+ end
244
+
245
+ context "when given a non-working day that is not a holiday day" do
246
+ let(:day) { date_class.parse("9am, Saturday 5th Jan, 2013") }
247
+ it { is_expected.to be_falsey }
248
+ end
249
+
250
+ context "when given a day that is a holiday" do
251
+ let(:day) { date_class.parse("9am, Tuesday 1st Jan, 2013") }
252
+ it { is_expected.to be_truthy }
253
+ end
254
+
255
+ context "when given a non-business day that is no a holiday" do
256
+ let(:day) { date_class.parse("9am, Sunday 6th Jan, 2013") }
257
+ it { is_expected.to be_falsey }
258
+ end
259
+ end
260
+
205
261
  describe "#roll_forward" do
206
262
  let(:calendar) do
207
263
  Business::Calendar.new(holidays: ["Tuesday 1st Jan, 2013"])
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Marr
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-06-08 00:00:00.000000000 Z
@@ -64,7 +64,7 @@ homepage: https://github.com/gocardless/business
64
64
  licenses:
65
65
  - MIT
66
66
  metadata: {}
67
- post_install_message:
67
+ post_install_message:
68
68
  rdoc_options: []
69
69
  require_paths:
70
70
  - lib
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubygems_version: 3.1.2
83
- signing_key:
83
+ signing_key:
84
84
  specification_version: 4
85
85
  summary: Date calculations based on business calendars
86
86
  test_files: