business_calendar 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/data/org/captalys.yml +79 -0
- data/lib/business_calendar.rb +27 -0
- data/lib/business_calendar/version.rb +1 -1
- data/spec/acceptance_organization_spec.rb +65 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd465969e54c82daeb4bab3cf79c057ea98a82217c9ac21c7e18c3e85b646be3
|
4
|
+
data.tar.gz: 5bea806cad1523d54e768970aae19267946d1785bf311af50033543d978fbe00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 194d44405e1c634c8a2f66e14b3085a804c0caebfd1a665ad3d09b94797cc04c6c833a4de6aa944849374334790329f964f141cda255d9b9e59cada605125858
|
7
|
+
data.tar.gz: 2fc970adc520f9b2583d088a3b8b6b9ccf8fdbf9af69062df114a776825b643ba7c46e91fdb00ae3d1ff5fd605f95238978d12082e93a43e6a963e2503f28603
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# +additions_only+ will tell business_calendar to not attempt to fetch holidays from the underlying
|
2
|
+
# `holidays` gem, and instead only use the defined +additions+ here. Useful e.g. for cases where a
|
3
|
+
# country is not even defined in the `holidays` gem.
|
4
|
+
# Defaults to `false`
|
5
|
+
|
6
|
+
captalys:
|
7
|
+
regions:
|
8
|
+
- br
|
9
|
+
additions:
|
10
|
+
- '2017-01-01'
|
11
|
+
- '2017-01-25'
|
12
|
+
- '2017-02-27'
|
13
|
+
- '2017-02-28'
|
14
|
+
- '2017-04-14'
|
15
|
+
- '2017-04-21'
|
16
|
+
- '2017-05-01'
|
17
|
+
- '2017-06-15'
|
18
|
+
- '2017-09-07'
|
19
|
+
- '2017-10-12'
|
20
|
+
- '2017-11-02'
|
21
|
+
- '2017-11-15'
|
22
|
+
- '2017-11-20'
|
23
|
+
- '2017-12-25'
|
24
|
+
- '2018-01-01'
|
25
|
+
- '2018-01-25'
|
26
|
+
- '2018-02-12'
|
27
|
+
- '2018-02-13'
|
28
|
+
- '2018-03-30'
|
29
|
+
- '2018-04-21'
|
30
|
+
- '2018-05-01'
|
31
|
+
- '2018-05-31'
|
32
|
+
- '2018-09-07'
|
33
|
+
- '2018-10-12'
|
34
|
+
- '2018-11-02'
|
35
|
+
- '2018-11-15'
|
36
|
+
- '2018-11-20'
|
37
|
+
- '2018-12-25'
|
38
|
+
- '2019-01-01'
|
39
|
+
- '2019-01-25'
|
40
|
+
- '2019-03-04'
|
41
|
+
- '2019-03-05'
|
42
|
+
- '2019-04-19'
|
43
|
+
- '2019-04-21'
|
44
|
+
- '2019-05-01'
|
45
|
+
- '2019-06-20'
|
46
|
+
- '2019-09-07'
|
47
|
+
- '2019-10-12'
|
48
|
+
- '2019-11-02'
|
49
|
+
- '2019-11-15'
|
50
|
+
- '2019-11-20'
|
51
|
+
- '2019-12-25'
|
52
|
+
- '2020-01-01'
|
53
|
+
- '2020-01-25'
|
54
|
+
- '2020-02-24'
|
55
|
+
- '2020-02-25'
|
56
|
+
- '2020-04-10'
|
57
|
+
- '2020-04-21'
|
58
|
+
- '2020-05-01'
|
59
|
+
- '2020-06-11'
|
60
|
+
- '2020-09-07'
|
61
|
+
- '2020-10-12'
|
62
|
+
- '2020-11-02'
|
63
|
+
- '2020-11-15'
|
64
|
+
- '2020-11-20'
|
65
|
+
- '2020-12-25'
|
66
|
+
- '2021-01-01'
|
67
|
+
- '2021-01-25'
|
68
|
+
- '2021-02-15'
|
69
|
+
- '2021-02-16'
|
70
|
+
- '2021-04-02'
|
71
|
+
- '2021-04-21'
|
72
|
+
- '2021-05-01'
|
73
|
+
- '2021-06-03'
|
74
|
+
- '2021-09-07'
|
75
|
+
- '2021-10-12'
|
76
|
+
- '2021-11-02'
|
77
|
+
- '2021-11-15'
|
78
|
+
- '2021-11-20'
|
79
|
+
- '2021-12-25'
|
data/lib/business_calendar.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
module BusinessCalendar
|
2
2
|
CountryNotSupported = Class.new(StandardError)
|
3
|
+
OrganizationNotSupported = Class.new(StandardError)
|
3
4
|
class << self
|
4
5
|
def for(country)
|
5
6
|
Calendar.new(holiday_determiner(country))
|
6
7
|
end
|
7
8
|
|
9
|
+
def for_organization(org)
|
10
|
+
Calendar.new(holiday_determiner_for_organization(org))
|
11
|
+
end
|
12
|
+
|
8
13
|
private
|
9
14
|
|
10
15
|
def holiday_determiner(country)
|
@@ -18,6 +23,17 @@ module BusinessCalendar
|
|
18
23
|
:additions_only => cfg['additions_only'] )
|
19
24
|
end
|
20
25
|
|
26
|
+
def holiday_determiner_for_organization(org)
|
27
|
+
cfg = org_config(org) or raise OrganizationNotSupported.new(org.inspect)
|
28
|
+
@holiday_procs ||= {}
|
29
|
+
@holiday_procs[org] ||= HolidayDeterminer.new(
|
30
|
+
cfg["regions"],
|
31
|
+
cfg["holiday_names"],
|
32
|
+
:additions => (cfg["additions"] || []).map { |s| Date.parse s },
|
33
|
+
:removals => (cfg["removals"] || []).map { |s| Date.parse s },
|
34
|
+
:additions_only => cfg['additions_only'] )
|
35
|
+
end
|
36
|
+
|
21
37
|
def config(country)
|
22
38
|
@config ||= load_config
|
23
39
|
@config[country.to_s]
|
@@ -28,6 +44,17 @@ module BusinessCalendar
|
|
28
44
|
|
29
45
|
files.reduce({}) { |hash, file| hash.merge! YAML.load_file(file) }
|
30
46
|
end
|
47
|
+
|
48
|
+
def org_config(org)
|
49
|
+
@org_config ||= load_config_for_organizations
|
50
|
+
@org_config[org.to_s]
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_config_for_organizations
|
54
|
+
files = Dir[File.join(File.dirname(File.expand_path(__FILE__)), '../data/org/*.yml')]
|
55
|
+
|
56
|
+
files.reduce({}) { |hash, file| hash.merge! YAML.load_file(file) }
|
57
|
+
end
|
31
58
|
end
|
32
59
|
end
|
33
60
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Organization bank holidays" do
|
4
|
+
%w(
|
5
|
+
2017-01-01
|
6
|
+
2017-01-25
|
7
|
+
2017-02-27
|
8
|
+
2017-02-28
|
9
|
+
2017-04-14
|
10
|
+
2017-04-21
|
11
|
+
2017-05-01
|
12
|
+
2017-06-15
|
13
|
+
2017-09-07
|
14
|
+
2017-10-12
|
15
|
+
2017-11-02
|
16
|
+
2017-11-15
|
17
|
+
2017-11-20
|
18
|
+
2017-12-25
|
19
|
+
2018-01-01
|
20
|
+
2018-01-25
|
21
|
+
2018-02-12
|
22
|
+
2018-02-13
|
23
|
+
2018-03-30
|
24
|
+
2018-04-21
|
25
|
+
2018-05-01
|
26
|
+
2018-05-31
|
27
|
+
2018-09-07
|
28
|
+
2018-10-12
|
29
|
+
2018-11-02
|
30
|
+
2018-11-15
|
31
|
+
2018-11-20
|
32
|
+
2018-12-25
|
33
|
+
).map { |x| Date.parse x }.each do |expected_holiday|
|
34
|
+
it "treats #{expected_holiday} as a holiday" do
|
35
|
+
expect(BusinessCalendar.for_organization(:captalys).is_holiday?(expected_holiday)).to be true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
%w(
|
40
|
+
2018-12-26
|
41
|
+
2017-01-02
|
42
|
+
).map { |x| Date.parse x }.each do |date|
|
43
|
+
it "treats #{date} as not a holiday" do
|
44
|
+
expect(BusinessCalendar.for_organization(:captalys).is_holiday?(date)).to be false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Saturday and Sunday
|
49
|
+
%w(
|
50
|
+
2018-11-25
|
51
|
+
2017-11-26
|
52
|
+
).map { |x| Date.parse x }.each do |date|
|
53
|
+
it "treats #{date} as not a business day" do
|
54
|
+
expect(BusinessCalendar.for_organization(:captalys).is_business_day?(date)).to be false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "calculates previous business day correctly" do
|
59
|
+
expect(BusinessCalendar.for_organization(:captalys).preceding_business_day(Date.parse('2018-11-19'))).to eq (Date.parse('2018-11-16'))
|
60
|
+
end
|
61
|
+
|
62
|
+
it "calculates next business day correctly" do
|
63
|
+
expect(BusinessCalendar.for_organization(:captalys).following_business_day(Date.parse('2018-11-19'))).to eq (Date.parse('2018-11-21'))
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Nubel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: holidays
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- data/CN.yml
|
116
116
|
- data/GB.yml
|
117
117
|
- data/US.yml
|
118
|
+
- data/org/captalys.yml
|
118
119
|
- gemfiles/ree.gemfile
|
119
120
|
- lib/business_calendar.rb
|
120
121
|
- lib/business_calendar/calendar.rb
|
@@ -124,6 +125,7 @@ files:
|
|
124
125
|
- spec/acceptance_br_spec.rb
|
125
126
|
- spec/acceptance_cn_spec.rb
|
126
127
|
- spec/acceptance_gb_spec.rb
|
128
|
+
- spec/acceptance_organization_spec.rb
|
127
129
|
- spec/acceptance_us_spec.rb
|
128
130
|
- spec/business_calendar/holiday_determiner_spec.rb
|
129
131
|
- spec/business_calendar_spec.rb
|
@@ -148,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
150
|
version: '0'
|
149
151
|
requirements: []
|
150
152
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.7.6
|
152
154
|
signing_key:
|
153
155
|
specification_version: 4
|
154
156
|
summary: Country-aware business-date logic and handling.
|
@@ -156,6 +158,7 @@ test_files:
|
|
156
158
|
- spec/acceptance_br_spec.rb
|
157
159
|
- spec/acceptance_cn_spec.rb
|
158
160
|
- spec/acceptance_gb_spec.rb
|
161
|
+
- spec/acceptance_organization_spec.rb
|
159
162
|
- spec/acceptance_us_spec.rb
|
160
163
|
- spec/business_calendar/holiday_determiner_spec.rb
|
161
164
|
- spec/business_calendar_spec.rb
|