business 2.2.1 → 2.3.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 +4 -4
- data/.circleci/config.yml +2 -2
- data/.github/dependabot.yml +7 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +7 -0
- data/business.gemspec +3 -3
- data/lib/business/calendar.rb +4 -8
- data/lib/business/version.rb +1 -1
- data/spec/business/calendar_spec.rb +5 -2
- data/spec/fixtures/calendars/ecb.yml +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b251f5b883fe268c312d1d85b129f20244ca8729a427784f8e5c0b87681ff646
|
4
|
+
data.tar.gz: '05779798d8c21739f31a604b6e46c063f62189b0a7e0a1064e674c1c5fbe9278'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d117a929340ee63c4978d6a0869e3e99fb585c002ac609a9d12d047aee7a96f75fc04f7a03bda894591348d23a3d3f43a32c1e33366d2bdb77d2ce9481c7e21
|
7
|
+
data.tar.gz: b2b9acd515306f0460e3e48aa89a0c0296b8bd9eebf9a4b51a4a3731fd94b7096ca521fd50db9ace4ba97bbcb7bb24e17cc6d38c488e6855bc8b34c1d0cd982f
|
data/.circleci/config.yml
CHANGED
@@ -3,7 +3,7 @@ version: 2.1
|
|
3
3
|
jobs:
|
4
4
|
test:
|
5
5
|
docker:
|
6
|
-
- image:
|
6
|
+
- image: cimg/ruby:<< parameters.ruby-version >>
|
7
7
|
parameters:
|
8
8
|
ruby-version:
|
9
9
|
type: string
|
@@ -34,4 +34,4 @@ workflows:
|
|
34
34
|
name: Ruby << matrix.ruby-version >>
|
35
35
|
matrix:
|
36
36
|
parameters:
|
37
|
-
ruby-version: ["2.
|
37
|
+
ruby-version: ["2.6.7", "2.7.3", "3.0.1", "3.1.0"]
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.0
|
data/CHANGELOG.md
CHANGED
data/business.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_development_dependency "gc_ruboconfig", "~> 2.
|
23
|
+
spec.add_development_dependency "gc_ruboconfig", "~> 2.31.0"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.1"
|
25
|
-
spec.add_development_dependency "rspec_junit_formatter", "~> 0.
|
26
|
-
spec.add_development_dependency "rubocop", "~> 1.
|
25
|
+
spec.add_development_dependency "rspec_junit_formatter", "~> 0.5.1"
|
26
|
+
spec.add_development_dependency "rubocop", "~> 1.25.0"
|
27
27
|
end
|
data/lib/business/calendar.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "yaml"
|
4
4
|
require "date"
|
5
|
+
require "pathname"
|
5
6
|
|
6
7
|
module Business
|
7
8
|
class Calendar
|
@@ -16,7 +17,6 @@ module Business
|
|
16
17
|
end
|
17
18
|
private_class_method :calendar_directories
|
18
19
|
|
19
|
-
# rubocop:disable Metrics/MethodLength
|
20
20
|
def self.load(calendar_name)
|
21
21
|
data = find_calendar_data(calendar_name)
|
22
22
|
raise "No such calendar '#{calendar_name}'" unless data
|
@@ -32,16 +32,16 @@ module Business
|
|
32
32
|
extra_working_dates: data["extra_working_dates"],
|
33
33
|
)
|
34
34
|
end
|
35
|
-
# rubocop:enable Metrics/MethodLength
|
36
35
|
|
37
36
|
def self.find_calendar_data(calendar_name)
|
38
37
|
calendar_directories.detect do |path|
|
39
38
|
if path.is_a?(Hash)
|
40
39
|
break path[calendar_name] if path[calendar_name]
|
41
40
|
else
|
42
|
-
|
41
|
+
calendar_path = Pathname.new(path).join("#{calendar_name}.yml")
|
42
|
+
next unless calendar_path.exist?
|
43
43
|
|
44
|
-
break YAML.
|
44
|
+
break YAML.safe_load(calendar_path.read, permitted_classes: [Date])
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -156,8 +156,6 @@ module Business
|
|
156
156
|
# Count the number of business days between two dates.
|
157
157
|
# This method counts from start of date1 to start of date2. So,
|
158
158
|
# business_days_between(mon, weds) = 2 (assuming no holidays)
|
159
|
-
# rubocop:disable Metrics/AbcSize
|
160
|
-
# rubocop:disable Metrics/MethodLength
|
161
159
|
def business_days_between(date1, date2)
|
162
160
|
date1 = date1.to_date
|
163
161
|
date2 = date2.to_date
|
@@ -190,8 +188,6 @@ module Business
|
|
190
188
|
# Loop through each day in remaining_range and count if a business day
|
191
189
|
num_biz_days + remaining_range.count { |a| business_day?(a) }
|
192
190
|
end
|
193
|
-
# rubocop:enable Metrics/AbcSize
|
194
|
-
# rubocop:enable Metrics/MethodLength
|
195
191
|
|
196
192
|
def day_interval_for(date)
|
197
193
|
date.is_a?(Date) ? 1 : 3600 * 24
|
data/lib/business/version.rb
CHANGED
@@ -13,9 +13,9 @@ RSpec.describe Business::Calendar do
|
|
13
13
|
subject(:load_calendar) { described_class.load(calendar) }
|
14
14
|
|
15
15
|
let(:dummy_calendar) { { "working_days" => ["monday"] } }
|
16
|
+
let(:fixture_path) { File.join(File.dirname(__FILE__), "../fixtures", "calendars") }
|
16
17
|
|
17
18
|
before do
|
18
|
-
fixture_path = File.join(File.dirname(__FILE__), "../fixtures", "calendars")
|
19
19
|
described_class.load_paths = [fixture_path, { "foobar" => dummy_calendar }]
|
20
20
|
end
|
21
21
|
|
@@ -25,7 +25,10 @@ RSpec.describe Business::Calendar do
|
|
25
25
|
after { described_class.load_paths = nil }
|
26
26
|
|
27
27
|
it "loads the yaml file" do
|
28
|
-
|
28
|
+
path = Pathname.new(fixture_path).join("ecb.yml")
|
29
|
+
expect(YAML).to receive(:safe_load).
|
30
|
+
with(path.read, permitted_classes: [Date]).
|
31
|
+
and_return({})
|
29
32
|
|
30
33
|
load_calendar
|
31
34
|
end
|
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: 2.
|
4
|
+
version: 2.3.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:
|
11
|
+
date: 2022-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gc_ruboconfig
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.31.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.31.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.5.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.5.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.25.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.25.0
|
69
69
|
description: Date calculations based on business calendars
|
70
70
|
email:
|
71
71
|
- developers@gocardless.com
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".circleci/config.yml"
|
77
|
+
- ".github/dependabot.yml"
|
77
78
|
- ".gitignore"
|
78
79
|
- ".rubocop.yml"
|
79
80
|
- ".ruby-version"
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
- !ruby/object:Gem::Version
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.3.3
|
112
113
|
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: Date calculations based on business calendars
|