business 1.12.0 → 1.13.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
- SHA1:
3
- metadata.gz: 1431e1fe213a16dbbf8dbf725fb5efcf034835cf
4
- data.tar.gz: 1795c1836084a2c2b5730b1caa7f96641d86185a
2
+ SHA256:
3
+ metadata.gz: 2ce183fd075a28db58cdae3a9f4c1815544866a171f7ef452b2600a9e33d4a2f
4
+ data.tar.gz: 96e32b1777a865e52aa54c2b795ddb0402bbcc68baf4d0419aedb3046c34c354
5
5
  SHA512:
6
- metadata.gz: ba2842e349db5f8195eea673a95cc3d9d47a9f85d9b0168e80179421030895ef0cfbe4848f98d80defc3e70ef19fa91fc3fa14e355982035c6d5520d05c205bd
7
- data.tar.gz: f7a0973d56bdec053c85ee06874175b3ddaed412597079cd34dc48164403d143584f0bc2a9e155af44038719910b0134afa90e6e746836816a6b53b480b67c56
6
+ metadata.gz: fe6c860087c55a924c49eca49306b20971bccca378b4da72f62b24c13179bb6e9c08cee1d3ec821dd9ea034b6a3169d926b352ff4ec355a1b002e2919fb5637e
7
+ data.tar.gz: 0d45896c08651c3af203cfd331dbe449e62edf00c45e2bc0487aa0d805408f8b4726ed1ed96cc9bbe21f839bcbac7ac35cbf7de4df927a9cb70c02cdc03ca1c7
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ ruby-2.5.1
data/.travis.yml CHANGED
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.4.1
5
- - 2.3.4
6
- - 2.2.7
4
+ - 2.5.1
5
+ - 2.4.3
6
+ - 2.3.7
7
+ - 2.2.10
7
8
  - 2.1.10
8
9
 
9
10
  sudo: false
data/CHANGELOG.md CHANGED
@@ -1,7 +1,23 @@
1
+ ## 1.13.0 - April 17, 2018
2
+
3
+ - Add support for specifying `extra_working_dates` (special dates that are "working days",
4
+ even though they are not one of the specified days, for example weekend dates
5
+ that are considered to be working days)
6
+
7
+ ## 1.12.0 - April 3, 2018
8
+
9
+ - Add Betalingservice & BECS calendars up until 2020
10
+
1
11
  ## 1.11.1 - December 20, 2017
2
12
 
3
13
  - Add 2017-2018 BECS holiday definitions
4
14
 
15
+ ## 1.11.0 - December 13, 2017
16
+
17
+ - Handle properly calendar initialization by Date objects (not strings),
18
+ coming from both YAML config and initialize().
19
+
20
+
5
21
  ## 1.10.0 - September 20, 2017
6
22
 
7
23
  - Add 2018-2019 Betalingsservice holiday definitions
data/README.md CHANGED
@@ -22,11 +22,13 @@ days, and which days are holidays.
22
22
  ```ruby
23
23
  calendar = Business::Calendar.new(
24
24
  working_days: %w( mon tue wed thu fri ),
25
- holidays: ["01/01/2014", "03/01/2014"]
25
+ holidays: ["01/01/2014", "03/01/2014"] # array items are either parseable date strings, or real Date objects
26
26
  )
27
27
  ```
28
28
 
29
- A few calendar configs are bundled with the gem (see lib/business/data for
29
+ `extra_working_dates` key makes the calendar to consider a weekend day as a working day.
30
+
31
+ A few calendar configs are bundled with the gem (see [lib/business/data]((lib/business/data)) for
30
32
  details). Load them by calling the `load` class method on `Calendar`. The
31
33
  `load_cached` variant of this method caches the calendars by name after loading
32
34
  them, to avoid reading and parsing the config file multiple times.
@@ -36,11 +38,24 @@ calendar = Business::Calendar.load("weekdays")
36
38
  calendar = Business::Calendar.load_cached("weekdays")
37
39
  ```
38
40
 
41
+ If `working_days` is missing, then common default is used (mon-fri).
42
+ If `holidays` is missing, "no holidays" assumed.
43
+ If `extra_working_dates` is missing, then no changes in `working_days` will happen.
44
+
45
+ Elements of `holidays` and `extra_working_dates` may be
46
+ eiter strings that `Date.parse()` can understand,
47
+ or YYYY-MM-DD (which is considered as a Date by Ruby YAML itself).
48
+
49
+ ```yaml
50
+ holidays:
51
+ - 2017-01-08 # Same as January 8th, 2017
52
+ ```
53
+
39
54
  ### Checking for business days
40
55
 
41
56
  To check whether a given date is a business day (falls on one of the specified
42
- working days, and is not a holiday), use the `business_day?` method on
43
- `Calendar`.
57
+ working days or working dates, and is not a holiday), use the `business_day?`
58
+ method on `Calendar`.
44
59
 
45
60
  ```ruby
46
61
  calendar.business_day?(Date.parse("Monday, 9 June 2014"))
@@ -19,13 +19,14 @@ module Business
19
19
  raise "No such calendar '#{calendar}'" unless directory
20
20
 
21
21
  yaml = YAML.load_file(File.join(directory, "#{calendar}.yml"))
22
- valid_keys = ['holidays', 'working_days']
22
+ valid_keys = %w(holidays working_days extra_working_dates)
23
23
 
24
24
  unless (yaml.keys - valid_keys).empty?
25
25
  raise "Only valid keys are: #{valid_keys.join(', ')}"
26
26
  end
27
-
28
- self.new(holidays: yaml['holidays'], working_days: yaml['working_days'])
27
+
28
+ self.new(holidays: yaml['holidays'], working_days: yaml['working_days'],
29
+ extra_working_dates: yaml['extra_working_dates'])
29
30
  end
30
31
 
31
32
  @lock = Mutex.new
@@ -41,9 +42,10 @@ module Business
41
42
 
42
43
  DAY_NAMES = %( mon tue wed thu fri sat sun )
43
44
 
44
- attr_reader :working_days, :holidays
45
+ attr_reader :holidays, :working_days, :extra_working_dates
45
46
 
46
47
  def initialize(config)
48
+ set_extra_working_dates(config[:extra_working_dates])
47
49
  set_working_days(config[:working_days])
48
50
  set_holidays(config[:holidays])
49
51
  end
@@ -52,6 +54,7 @@ module Business
52
54
  # non-weekend day) and not a holiday.
53
55
  def business_day?(date)
54
56
  date = date.to_date
57
+ return true if extra_working_dates.include?(date)
55
58
  return false unless working_days.include?(date.strftime('%a').downcase)
56
59
  return false if holidays.include?(date)
57
60
  true
@@ -167,11 +170,24 @@ module Business
167
170
  raise "Invalid day #{day}" unless DAY_NAMES.include?(normalised_day)
168
171
  end
169
172
  end
173
+ extra_working_dates_names = @extra_working_dates.map { |d| d.strftime("%a").downcase }
174
+ return if (extra_working_dates_names & @working_days).none?
175
+ raise ArgumentError, 'Extra working dates cannot be on working days'
176
+ end
177
+
178
+ def parse_dates(dates)
179
+ (dates || []).map { |date| date.is_a?(Date) ? date : Date.parse(date) }
170
180
  end
171
181
 
172
182
  # Internal method for assigning holidays from a calendar config.
173
183
  def set_holidays(holidays)
174
- @holidays = (holidays || []).map { |holiday| Date.parse(holiday) }
184
+ @holidays = parse_dates(holidays)
185
+ return if (@holidays & @extra_working_dates).none?
186
+ raise ArgumentError, 'Holidays cannot be extra working dates'
187
+ end
188
+
189
+ def set_extra_working_dates(extra_working_dates)
190
+ @extra_working_dates = parse_dates(extra_working_dates)
175
191
  end
176
192
 
177
193
  # If no working days are provided in the calendar config, these are used.
@@ -180,4 +196,3 @@ module Business
180
196
  end
181
197
  end
182
198
  end
183
-
@@ -1,3 +1,3 @@
1
1
  module Business
2
- VERSION = "1.12.0"
2
+ VERSION = "1.13.0"
3
3
  end
@@ -56,7 +56,7 @@ describe Business::Calendar do
56
56
 
57
57
  context "when given a calendar that has invalid keys" do
58
58
  subject { Business::Calendar.load("invalid-keys") }
59
- specify { expect { subject }.to raise_error("Only valid keys are: holidays, working_days") }
59
+ specify { expect { subject }.to raise_error("Only valid keys are: holidays, working_days, extra_working_dates") }
60
60
  end
61
61
 
62
62
  context "when given real business data" do
@@ -72,6 +72,19 @@ describe Business::Calendar do
72
72
  end
73
73
  end
74
74
 
75
+ describe "bundled calendars" do
76
+ calendars = Dir.glob("../lib/business/data*.yml")
77
+ .map { |f| File.basename(f, ".yml") }
78
+
79
+ calendars.each do |calendar|
80
+ describe calendar do
81
+ it "should load without issues" do
82
+ expect { Business::Calendar.load(calendar) }.not_to raise_error
83
+ end
84
+ end
85
+ end
86
+ end
87
+
75
88
  describe "#set_working_days" do
76
89
  let(:calendar) { Business::Calendar.new({}) }
77
90
  let(:working_days) { [] }
@@ -128,13 +141,60 @@ describe Business::Calendar do
128
141
  end
129
142
  end
130
143
 
144
+ describe "#set_extra_working_dates" do
145
+ let(:calendar) { Business::Calendar.new({}) }
146
+ let(:extra_working_dates) { [] }
147
+ before { calendar.set_extra_working_dates(extra_working_dates) }
148
+ subject { calendar.extra_working_dates }
149
+
150
+ context "when given valid business days" do
151
+ let(:extra_working_dates) { ["1st Jan, 2013"] }
152
+
153
+ it { is_expected.not_to be_empty }
154
+
155
+ it "converts them to Date objects" do
156
+ subject.each { |h| expect(h).to be_a Date }
157
+ end
158
+ end
159
+
160
+ context "when given nil" do
161
+ let(:holidays) { nil }
162
+ it { is_expected.to be_empty }
163
+ end
164
+ end
165
+
166
+ context "when holiday is also a working date" do
167
+ subject do
168
+ Business::Calendar.new(holidays: ["2018-01-06"],
169
+ extra_working_dates: ["2018-01-06"])
170
+ end
171
+
172
+ it do
173
+ expect { subject }.to raise_error(ArgumentError)
174
+ .with_message('Holidays cannot be extra working dates')
175
+ end
176
+ end
177
+
178
+ context "when working date on working day" do
179
+ subject do
180
+ Business::Calendar.new(working_days: ["mon"],
181
+ extra_working_dates: ["Monday 26th Mar, 2018"])
182
+ end
183
+
184
+ it do
185
+ expect { subject }.to raise_error(ArgumentError)
186
+ .with_message('Extra working dates cannot be on working days')
187
+ end
188
+ end
189
+
131
190
  # A set of examples that are supposed to work when given Date and Time
132
191
  # objects. The implementation slightly differs, so i's worth running the
133
192
  # tests for both Date *and* Time.
134
193
  shared_examples "common" do
135
194
  describe "#business_day?" do
136
195
  let(:calendar) do
137
- Business::Calendar.new(holidays: ["9am, Tuesday 1st Jan, 2013"])
196
+ Business::Calendar.new(holidays: ["9am, Tuesday 1st Jan, 2013"],
197
+ extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
138
198
  end
139
199
  subject { calendar.business_day?(day) }
140
200
 
@@ -152,6 +212,11 @@ describe Business::Calendar do
152
212
  let(:day) { date_class.parse("9am, Tuesday 1st Jan, 2013") }
153
213
  it { is_expected.to be_falsey }
154
214
  end
215
+
216
+ context "when given a non-business day that is a working date" do
217
+ let(:day) { date_class.parse("9am, Sunday 6th Jan, 2013") }
218
+ it { is_expected.to be_truthy }
219
+ end
155
220
  end
156
221
 
157
222
  describe "#roll_forward" do
@@ -251,8 +316,10 @@ describe Business::Calendar do
251
316
  end
252
317
 
253
318
  describe "#add_business_days" do
319
+ let(:extra_working_dates) { [] }
254
320
  let(:calendar) do
255
- Business::Calendar.new(holidays: ["Tuesday 1st Jan, 2013"])
321
+ Business::Calendar.new(holidays: ["Tuesday 1st Jan, 2013"],
322
+ extra_working_dates: extra_working_dates)
256
323
  end
257
324
  let(:delta) { 2 }
258
325
  subject { calendar.add_business_days(date, delta) }
@@ -268,6 +335,12 @@ describe Business::Calendar do
268
335
  it { is_expected.to eq(date + (delta + 2) * day_interval) }
269
336
  end
270
337
 
338
+ context "and a period that includes a working date weekend" do
339
+ let(:extra_working_dates) { ["Sunday 6th Jan, 2013"] }
340
+ let(:date) { date_class.parse("Friday 4th Jan, 2013") }
341
+ it { is_expected.to eq(date + (delta + 1) * day_interval) }
342
+ end
343
+
271
344
  context "and a period that includes a holiday day" do
272
345
  let(:date) { date_class.parse("Monday 31st Dec, 2012") }
273
346
  it { is_expected.to eq(date + (delta + 1) * day_interval) }
@@ -281,8 +354,10 @@ describe Business::Calendar do
281
354
  end
282
355
 
283
356
  describe "#subtract_business_days" do
357
+ let(:extra_working_dates) { [] }
284
358
  let(:calendar) do
285
- Business::Calendar.new(holidays: ["Thursday 3rd Jan, 2013"])
359
+ Business::Calendar.new(holidays: ["Thursday 3rd Jan, 2013"],
360
+ extra_working_dates: extra_working_dates)
286
361
  end
287
362
  let(:delta) { 2 }
288
363
  subject { calendar.subtract_business_days(date, delta) }
@@ -298,6 +373,12 @@ describe Business::Calendar do
298
373
  it { is_expected.to eq(date - (delta + 2) * day_interval) }
299
374
  end
300
375
 
376
+ context "and a period that includes a working date weekend" do
377
+ let(:extra_working_dates) { ["Saturday 29th Dec, 2012"] }
378
+ let(:date) { date_class.parse("Monday 31st Dec, 2012") }
379
+ it { is_expected.to eq(date - (delta + 1) * day_interval) }
380
+ end
381
+
301
382
  context "and a period that includes a holiday day" do
302
383
  let(:date) { date_class.parse("Friday 4th Jan, 2013") }
303
384
  it { is_expected.to eq(date - (delta + 1) * day_interval) }
@@ -312,146 +393,361 @@ describe Business::Calendar do
312
393
 
313
394
  describe "#business_days_between" do
314
395
  let(:holidays) do
315
- ["Thu 12/6/2014", "Wed 18/6/2014", "Fri 20/6/2014", "Sun 22/6/2014"]
396
+ ["Wed 27/5/2014", "Thu 12/6/2014", "Wed 18/6/2014", "Fri 20/6/2014",
397
+ "Sun 22/6/2014", "Fri 27/6/2014", "Thu 3/7/2014"]
398
+ end
399
+ let(:extra_working_dates) do
400
+ ["Sun 1/6/2014", "Sat 28/6/2014", "Sat 5/7/2014"]
401
+ end
402
+ let(:calendar) do
403
+ Business::Calendar.new(holidays: holidays, extra_working_dates: extra_working_dates)
404
+ end
405
+ subject do
406
+ calendar.business_days_between(date_class.parse(date_1),
407
+ date_class.parse(date_2))
316
408
  end
317
- let(:calendar) { Business::Calendar.new(holidays: holidays) }
318
- subject { calendar.business_days_between(date_1, date_2) }
319
-
320
409
 
321
410
  context "starting on a business day" do
322
- let(:date_1) { date_class.parse("Mon 2/6/2014") }
411
+ let(:date_1) { "Mon 2/6/2014" }
323
412
 
324
413
  context "ending on a business day" do
325
414
  context "including only business days" do
326
- let(:date_2) { date_class.parse("Thu 5/6/2014") }
415
+ let(:date_2) { "Thu 5/6/2014" }
327
416
  it { is_expected.to eq(3) }
328
417
  end
329
418
 
330
419
  context "including only business days & weekend days" do
331
- let(:date_2) { date_class.parse("Mon 9/6/2014") }
420
+ let(:date_2) { "Mon 9/6/2014" }
332
421
  it { is_expected.to eq(5) }
333
422
  end
334
423
 
424
+ context "including only business days, weekend days & working date" do
425
+ let(:date_1) { "Thu 29/5/2014" }
426
+ let(:date_2) { "The 3/6/2014" }
427
+ it { is_expected.to eql(4) }
428
+ end
429
+
335
430
  context "including only business days & holidays" do
336
- let(:date_1) { date_class.parse("Mon 9/6/2014") }
337
- let(:date_2) { date_class.parse("Fri 13/6/2014") }
431
+ let(:date_1) { "Mon 9/6/2014" }
432
+ let(:date_2) { "Fri 13/6/2014" }
338
433
  it { is_expected.to eq(3) }
339
434
  end
340
435
 
341
436
  context "including business, weekend days, and holidays" do
342
- let(:date_2) { date_class.parse("Fri 13/6/2014") }
437
+ let(:date_2) { "Fri 13/6/2014" }
343
438
  it { is_expected.to eq(8) }
344
439
  end
440
+
441
+ context "including business, weekend, hoilday days & working date" do
442
+ let(:date_1) { "Thu 26/6/2014" }
443
+ let(:date_2) { "The 1/7/2014" }
444
+ it { is_expected.to eql(3) }
445
+ end
345
446
  end
346
447
 
347
448
  context "ending on a weekend day" do
348
449
  context "including only business days & weekend days" do
349
- let(:date_2) { date_class.parse("Sun 8/6/2014") }
450
+ let(:date_2) { "Sun 8/6/2014" }
350
451
  it { is_expected.to eq(5) }
351
452
  end
352
453
 
454
+ context "including business & weekend days & working date" do
455
+ let(:date_1) { "Thu 29/5/2014" }
456
+ let(:date_2) { "Sun 3/6/2014" }
457
+ it { is_expected.to eq(4) }
458
+ end
459
+
353
460
  context "including business, weekend days, and holidays" do
354
- let(:date_2) { date_class.parse("Sat 14/6/2014") }
461
+ let(:date_2) { "Sat 14/6/2014" }
355
462
  it { is_expected.to eq(9) }
356
463
  end
464
+
465
+ context "including business, weekend & holiday days & working date" do
466
+ let(:date_1) { "Thu 26/6/2014" }
467
+ let(:date_2) { "Tue 2/7/2014" }
468
+ it { is_expected.to eq(4) }
469
+ end
357
470
  end
358
471
 
359
472
  context "ending on a holiday" do
360
473
  context "including only business days & holidays" do
361
- let(:date_1) { date_class.parse("Mon 9/6/2014") }
362
- let(:date_2) { date_class.parse("Thu 12/6/2014") }
474
+ let(:date_1) { "Mon 9/6/2014" }
475
+ let(:date_2) { "Thu 12/6/2014" }
363
476
  it { is_expected.to eq(3) }
364
477
  end
365
478
 
366
479
  context "including business, weekend days, and holidays" do
367
- let(:date_2) { date_class.parse("Thu 12/6/2014") }
480
+ let(:date_2) { "Thu 12/6/2014" }
481
+ it { is_expected.to eq(8) }
482
+ end
483
+
484
+ context 'including business, weekend, holiday days & business date' do
485
+ let(:date_1) { "Wed 28/5/2014" }
486
+ let(:date_2) { "Thu 12/6/2014" }
487
+ it { is_expected.to eq(11) }
488
+ end
489
+ end
490
+
491
+ context "ending on a working date" do
492
+ let(:date_1) { "Fri 4/7/2014" }
493
+
494
+ context "including only business days & working date" do
495
+ let(:date_2) { "Sat 5/7/2014" }
496
+ it { is_expected.to eq(1) }
497
+ end
498
+
499
+ context "including business, weekend days & working date" do
500
+ let(:date_2) { "Tue 8/7/2014" }
501
+ it { is_expected.to eq(3) }
502
+ end
503
+
504
+ context "including business, weekend days, holidays & working date" do
505
+ let(:date_1) { "Wed 25/6/2014" }
506
+ let(:date_2) { "Tue 8/7/2014" }
368
507
  it { is_expected.to eq(8) }
369
508
  end
370
509
  end
371
510
  end
372
511
 
373
512
  context "starting on a weekend" do
374
- let(:date_1) { date_class.parse("Sat 7/6/2014") }
513
+ let(:date_1) { "Sat 7/6/2014" }
375
514
 
376
515
  context "ending on a business day" do
377
516
 
378
517
  context "including only business days & weekend days" do
379
- let(:date_2) { date_class.parse("Mon 9/6/2014") }
518
+ let(:date_2) { "Mon 9/6/2014" }
380
519
  it { is_expected.to eq(0) }
381
520
  end
382
521
 
522
+ context "including business, weekend days & working date" do
523
+ let(:date_1) { "Sat 31/5/2014" }
524
+ let(:date_2) { "Tue 3/6/2014" }
525
+ it { is_expected.to eq(2) }
526
+ end
527
+
383
528
  context "including business, weekend days, and holidays" do
384
- let(:date_2) { date_class.parse("Fri 13/6/2014") }
529
+ let(:date_2) { "Fri 13/6/2014" }
385
530
  it { is_expected.to eq(3) }
386
531
  end
532
+
533
+ context "including business, weekend, holilday days & working date" do
534
+ let(:date_1) { "Sat 31/5/2014" }
535
+ let(:date_2) { "Fri 13/6/2014" }
536
+ it { is_expected.to eq(8) }
537
+ end
387
538
  end
388
539
 
389
540
  context "ending on a weekend day" do
390
541
  context "including only business days & weekend days" do
391
- let(:date_2) { date_class.parse("Sun 8/6/2014") }
542
+ let(:date_2) { "Sun 8/6/2014" }
392
543
  it { is_expected.to eq(0) }
393
544
  end
394
545
 
546
+ context "including business, weekend days & working date" do
547
+ let(:date_1) { "Sat 31/5/2014" }
548
+ let(:date_2) { "Sun 8/6/2014" }
549
+ it { is_expected.to eql(5) }
550
+ end
551
+
395
552
  context "including business, weekend days, and holidays" do
396
- let(:date_2) { date_class.parse("Sat 14/6/2014") }
553
+ let(:date_2) { "Sat 14/6/2014" }
397
554
  it { is_expected.to eq(4) }
398
555
  end
556
+
557
+ context "including business, weekend, holiday days & working date" do
558
+ let(:date_1) { "Sat 31/5/2014" }
559
+ let(:date_2) { "Sun 14/6/2014" }
560
+ it { is_expected.to eql(9) }
561
+ end
399
562
  end
400
563
 
401
564
  context "ending on a holiday" do
402
565
  context "including business, weekend days, and holidays" do
403
- let(:date_2) { date_class.parse("Thu 12/6/2014") }
566
+ let(:date_2) { "Thu 12/6/2014" }
567
+ it { is_expected.to eq(3) }
568
+ end
569
+
570
+ context "including business, weekend days & working date" do
571
+ let(:date_1) { "Sat 31/5/2014" }
572
+ let(:date_2) { "Thu 12/6/2014" }
573
+ it { is_expected.to eq(8) }
574
+ end
575
+ end
576
+
577
+ context "ending on a working date" do
578
+ let(:date_1) { "Sat 31/5/2014" }
579
+
580
+ context "including only weekend days & working date" do
581
+ let(:date_2) { "Sat 2/6/2014" }
582
+ it { is_expected.to eq(1) }
583
+ end
584
+
585
+ context "including business, weekend days & working date" do
586
+ let(:date_2) { "Tue 4/6/2014" }
404
587
  it { is_expected.to eq(3) }
405
588
  end
589
+
590
+ context "including business, weekend days, holidays & working date" do
591
+ let(:date_2) { "Tue 13/6/2014" }
592
+ it { is_expected.to eq(8) }
593
+ end
406
594
  end
407
595
  end
408
596
 
409
597
  context "starting on a holiday" do
410
- let(:date_1) { date_class.parse("Thu 12/6/2014") }
598
+ let(:date_1) { "Thu 12/6/2014" }
411
599
 
412
600
  context "ending on a business day" do
413
601
 
414
602
  context "including only business days & holidays" do
415
- let(:date_2) { date_class.parse("Fri 13/6/2014") }
603
+ let(:date_2) { "Fri 13/6/2014" }
416
604
  it { is_expected.to eq(0) }
417
605
  end
418
606
 
419
607
  context "including business, weekend days, and holidays" do
420
- let(:date_2) { date_class.parse("Thu 19/6/2014") }
608
+ let(:date_2) { "Thu 19/6/2014" }
421
609
  it { is_expected.to eq(3) }
422
610
  end
611
+
612
+ context "including business, weekend days, holidays & working date" do
613
+ let(:date_1) { "Fri 27/6/2014" }
614
+ let(:date_2) { "Tue 1/7/2014" }
615
+ it { is_expected.to eq(2) }
616
+ end
423
617
  end
424
618
 
425
619
  context "ending on a weekend day" do
426
620
  context "including business, weekend days, and holidays" do
427
- let(:date_2) { date_class.parse("Sun 15/6/2014") }
621
+ let(:date_2) { "Sun 15/6/2014" }
622
+ it { is_expected.to eq(1) }
623
+ end
624
+
625
+ context "including business, weekend days, holidays & working date" do
626
+ let(:date_1) { "Fri 27/6/2014" }
627
+ let(:date_2) { "Sun 29/6/2014" }
428
628
  it { is_expected.to eq(1) }
429
629
  end
430
630
  end
431
631
 
432
632
  context "ending on a holiday" do
433
633
  context "including only business days & holidays" do
434
- let(:date_1) { date_class.parse("Wed 18/6/2014") }
435
- let(:date_2) { date_class.parse("Fri 20/6/2014") }
634
+ let(:date_1) { "Wed 18/6/2014" }
635
+ let(:date_2) { "Fri 20/6/2014" }
436
636
  it { is_expected.to eq(1) }
437
637
  end
438
638
 
439
639
  context "including business, weekend days, and holidays" do
440
- let(:date_2) { date_class.parse("Wed 18/6/2014") }
640
+ let(:date_2) { "Wed 18/6/2014" }
641
+ it { is_expected.to eq(3) }
642
+ end
643
+
644
+ context "including business/weekend days, holidays & working date" do
645
+ let(:date_1) { "27/5/2014" }
646
+ let(:date_2) { "Thu 12/6/2014" }
647
+ it { is_expected.to eq(11) }
648
+ end
649
+ end
650
+
651
+ context "ending on a working date" do
652
+ let(:date_1) { "Sat 27/6/2014" }
653
+
654
+ context "including only holiday & working date" do
655
+ let(:date_2) { "Sat 29/6/2014" }
656
+ it { is_expected.to eq(1) }
657
+ end
658
+
659
+ context "including holiday, weekend days & working date" do
660
+ let(:date_2) { "Tue 30/6/2014" }
661
+ it { is_expected.to eq(1) }
662
+ end
663
+
664
+ context "including business, weekend days, holidays & working date" do
665
+ let(:date_2) { "Tue 2/7/2014" }
441
666
  it { is_expected.to eq(3) }
442
667
  end
443
668
  end
444
669
  end
445
670
 
671
+ context 'starting on a working date' do
672
+ let(:date_1) { "Sun 1/6/2014" }
673
+
674
+ context "ending on a working day" do
675
+ context "including only working date & working day" do
676
+ let(:date_2) { "Wed 4/6/2014" }
677
+ it { is_expected.to eq(3) }
678
+ end
679
+
680
+ context "including working date, working & weekend days" do
681
+ let(:date_2) { "Tue 10/6/2014" }
682
+ it { is_expected.to eq(6) }
683
+ end
684
+
685
+ context "including working date, working & weekend days & holiday" do
686
+ let(:date_2) { "Tue 13/6/2014" }
687
+ it { is_expected.to eq(8) }
688
+ end
689
+ end
690
+
691
+ context "ending on a weekend day" do
692
+ let(:date_1) { "Sat 28/6/2014" }
693
+
694
+ context "including only working date & weekend day" do
695
+ let(:date_2) { "Sun 29/6/2014" }
696
+ it { is_expected.to eq(1) }
697
+ end
698
+
699
+ context "including working date, weekend & working days" do
700
+ let(:date_1) { "Sat 5/7/2014" }
701
+ let(:date_2) { "Wed 9/7/2014" }
702
+ it { is_expected.to eq(3) }
703
+ end
704
+
705
+ context "including working date, weekend & working days & holiday" do
706
+ let(:date_2) { "Fri 4/7/2014" }
707
+ it { is_expected.to eq(4) }
708
+ end
709
+ end
710
+
711
+ context "ending on a holiday" do
712
+ let(:date_1) { "Sat 28/6/2014" }
713
+
714
+ context "including only working date & holiday" do
715
+ let(:holidays) { ["Mon 2/6/2014"] }
716
+ let(:date_1) { "Sun 1/6/2014" }
717
+ let(:date_2) { "Mon 2/6/2014" }
718
+ it { is_expected.to eq(1) }
719
+ end
720
+
721
+ context "including working date, holiday & weekend day" do
722
+ let(:holidays) { ["Mon 30/6/2014"] }
723
+ let(:date_2) { "Mon 30/6/2014" }
724
+ it { is_expected.to eq(1) }
725
+ end
726
+
727
+ context "including working date, holiday, weekend & working days" do
728
+ let(:date_2) { "Thu 3/7/2014" }
729
+ it { is_expected.to eq(4) }
730
+ end
731
+ end
732
+
733
+ context "ending on a working date" do
734
+ context "including working dates, weekend & working days" do
735
+ let(:date_1) { "Sat 28/6/2014" }
736
+ let(:date_2) { "Sat 5/7/2014" }
737
+ it { is_expected.to eq(4) }
738
+ end
739
+ end
740
+ end
741
+
446
742
  context "if a calendar has a holiday on a non-working (weekend) day" do
447
743
  context "for a range less than a week long" do
448
- let(:date_1) { date_class.parse("Thu 19/6/2014") }
449
- let(:date_2) { date_class.parse("Tue 24/6/2014") }
744
+ let(:date_1) { "Thu 19/6/2014" }
745
+ let(:date_2) { "Tue 24/6/2014" }
450
746
  it { is_expected.to eq(2) }
451
747
  end
452
748
  context "for a range more than a week long" do
453
- let(:date_1) { date_class.parse("Mon 16/6/2014") }
454
- let(:date_2) { date_class.parse("Tue 24/6/2014") }
749
+ let(:date_1) { "Mon 16/6/2014" }
750
+ let(:date_2) { "Tue 24/6/2014" }
455
751
  it { is_expected.to eq(4) }
456
752
  end
457
753
  end
@@ -479,4 +775,3 @@ describe Business::Calendar do
479
775
  it_behaves_like "common"
480
776
  end
481
777
  end
482
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Marr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-03 00:00:00.000000000 Z
11
+ date: 2018-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.6.11
89
+ rubygems_version: 2.7.6
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Date calculations based on business calendars