business_calendar 0.0.7 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,37 @@
1
1
  module BusinessCalendar
2
2
  CountryNotSupported = Class.new(StandardError)
3
+ class << self
4
+ def for(country)
5
+ Calendar.new(holiday_determiner(country))
6
+ end
3
7
 
4
- def self.for(country)
5
- Calendar.new(holiday_determiner(country))
6
- end
8
+ private
7
9
 
8
- private
9
- def self.holiday_determiner(country)
10
- cfg = config(country) or raise CountryNotSupported.new(country.inspect)
11
- @holiday_procs ||= {}
12
- @holiday_procs[country] ||= HolidayDeterminer.new(
13
- cfg["regions"],
14
- cfg["holiday_names"],
15
- :additions => (cfg["additions"] || []).map { |s| Date.parse s },
16
- :removals => (cfg["removals"] || []).map { |s| Date.parse s },
17
- :additions_only => cfg['additions_only'] )
18
- end
10
+ def holiday_determiner(country)
11
+ cfg = config(country) or raise CountryNotSupported.new(country.inspect)
12
+ @holiday_procs ||= {}
13
+ @holiday_procs[country] ||= HolidayDeterminer.new(
14
+ cfg["regions"],
15
+ cfg["holiday_names"],
16
+ :additions => (cfg["additions"] || []).map { |s| Date.parse s },
17
+ :removals => (cfg["removals"] || []).map { |s| Date.parse s },
18
+ :additions_only => cfg['additions_only'] )
19
+ end
20
+
21
+ def config(country)
22
+ @config ||= load_config
23
+ @config[country.to_s]
24
+ end
25
+
26
+ def load_config
27
+ files = Dir[File.join(File.dirname(File.expand_path(__FILE__)), '../data/*.yml')]
19
28
 
20
- def self.config(country)
21
- @config ||= YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), '../data/holidays.yml'))
22
- @config[country.to_s]
29
+ files.reduce({}) { |hash, file| hash.merge! YAML.load_file(file) }
30
+ end
23
31
  end
24
32
  end
25
33
 
26
34
  require 'yaml'
35
+ require 'business_calendar/ruby18_shim' if RUBY_VERSION == '1.8.7'
27
36
  require 'business_calendar/calendar'
28
37
  require 'business_calendar/holiday_determiner'
@@ -54,24 +54,24 @@ describe "CN holidays" do
54
54
  2016-01-01
55
55
  2016-01-02
56
56
  2016-01-03
57
- 2016-02-18
58
- 2016-02-19
59
- 2016-02-20
60
- 2016-02-21
61
- 2016-02-22
62
- 2016-02-23
63
- 2016-02-24
64
- 2016-04-05
65
- 2016-04-06
57
+ 2016-02-07
58
+ 2016-02-08
59
+ 2016-02-09
60
+ 2016-02-10
61
+ 2016-02-11
62
+ 2016-02-12
63
+ 2016-02-13
64
+ 2016-04-03
65
+ 2016-04-04
66
+ 2016-04-30
66
67
  2016-05-01
67
68
  2016-05-02
68
- 2016-05-03
69
- 2016-06-20
70
- 2016-06-21
71
- 2016-06-22
72
- 2016-09-27
73
- 2016-09-28
74
- 2016-09-29
69
+ 2016-06-09
70
+ 2016-06-10
71
+ 2016-06-11
72
+ 2016-09-15
73
+ 2016-09-16
74
+ 2016-09-17
75
75
  2016-10-01
76
76
  2016-10-02
77
77
  2016-10-03
@@ -79,6 +79,34 @@ describe "CN holidays" do
79
79
  2016-10-05
80
80
  2016-10-06
81
81
  2016-10-07
82
+ 2017-01-01
83
+ 2017-01-02
84
+ 2017-01-03
85
+ 2017-02-07
86
+ 2017-02-08
87
+ 2017-02-09
88
+ 2017-02-10
89
+ 2017-02-11
90
+ 2017-02-12
91
+ 2017-02-13
92
+ 2017-04-03
93
+ 2017-04-04
94
+ 2017-04-30
95
+ 2017-05-01
96
+ 2017-05-02
97
+ 2017-06-09
98
+ 2017-06-10
99
+ 2017-06-11
100
+ 2017-09-15
101
+ 2017-09-16
102
+ 2017-09-17
103
+ 2017-10-01
104
+ 2017-10-02
105
+ 2017-10-03
106
+ 2017-10-04
107
+ 2017-10-05
108
+ 2017-10-06
109
+ 2017-10-07
82
110
  ).map { |x| Date.parse x }.each do |expected_holiday|
83
111
  it "treats #{expected_holiday} as a holiday" do
84
112
  expect(BusinessCalendar.for(:CN).is_holiday?(expected_holiday)).to be true
@@ -17,7 +17,15 @@ describe "GB bank holidays" do
17
17
  2015-05-25
18
18
  2015-08-31
19
19
  2015-12-25
20
- 2015-12-28
20
+ 2015-12-26
21
+ 2016-12-25
22
+ 2017-01-01
23
+ 2020-12-26
24
+ 2021-12-25
25
+ 2021-12-26
26
+ 2022-01-01
27
+ 2022-12-25
28
+ 2023-01-01
21
29
  ).map { |x| Date.parse x }.each do |expected_holiday|
22
30
  it "treats #{expected_holiday} as a holiday" do
23
31
  expect(BusinessCalendar.for(:GB).is_holiday?(expected_holiday)).to be true
@@ -26,6 +34,15 @@ describe "GB bank holidays" do
26
34
 
27
35
  %w(
28
36
  2012-05-28
37
+ 2015-12-28
38
+ 2016-12-27
39
+ 2017-01-02
40
+ 2020-12-28
41
+ 2021-12-27
42
+ 2021-12-28
43
+ 2022-01-03
44
+ 2022-12-27
45
+ 2023-01-02
29
46
  ).map { |x| Date.parse x }.each do |date|
30
47
  it "treats #{date} as not a holiday" do
31
48
  expect(BusinessCalendar.for(:GB).is_holiday?(date)).to be false
@@ -2,45 +2,232 @@ require 'spec_helper'
2
2
 
3
3
  describe "US holidays" do
4
4
  %w(
5
- 2014-05-26
6
- 2014-07-04
7
- 2014-09-01
8
- 2014-10-13
9
- 2014-11-11
10
- 2014-11-27
11
- 2014-12-25
12
- 2015-01-01
13
- 2015-01-19
14
- 2015-02-16
15
- 2015-05-25
16
- 2015-07-03
17
- 2015-09-07
18
- 2015-10-12
19
- 2015-11-11
20
- 2015-11-26
21
- 2015-12-25
22
- 2016-01-01
23
- 2016-01-18
24
- 2016-02-15
25
- 2016-05-30
26
- 2016-07-04
27
- 2016-09-05
28
- 2016-10-10
29
- 2016-11-11
30
- 2016-11-24
31
- 2016-12-26
32
- 2017-01-02
33
- 2017-01-16
34
- 2017-02-20
35
- 2017-05-29
36
- 2017-07-04
37
- 2017-09-04
38
- 2017-10-09
39
- 2017-11-10
40
- 2017-11-23
41
- 2017-12-25
42
- 2018-01-01
43
- ).map { |x| Date.parse x }.each do |expected_holiday|
5
+ 2004-01-01
6
+ 2004-01-19
7
+ 2004-02-16
8
+ 2004-05-31
9
+ 2004-07-05
10
+ 2004-09-06
11
+ 2004-10-11
12
+ 2004-11-11
13
+ 2004-11-25
14
+ 2004-12-25
15
+ 2005-01-01
16
+ 2005-01-17
17
+ 2005-02-21
18
+ 2005-05-30
19
+ 2005-07-04
20
+ 2005-09-05
21
+ 2005-10-10
22
+ 2005-11-11
23
+ 2005-11-24
24
+ 2005-12-26
25
+ 2006-01-02
26
+ 2006-01-16
27
+ 2006-02-20
28
+ 2006-05-29
29
+ 2006-07-04
30
+ 2006-09-04
31
+ 2006-10-09
32
+ 2006-11-11
33
+ 2006-11-23
34
+ 2006-12-25
35
+ 2007-01-01
36
+ 2007-01-15
37
+ 2007-02-19
38
+ 2007-05-28
39
+ 2007-07-04
40
+ 2007-09-03
41
+ 2007-10-08
42
+ 2007-11-12
43
+ 2007-11-22
44
+ 2007-12-25
45
+ 2008-01-01
46
+ 2008-01-21
47
+ 2008-02-18
48
+ 2008-05-26
49
+ 2008-07-04
50
+ 2008-09-01
51
+ 2008-10-13
52
+ 2008-11-11
53
+ 2008-11-27
54
+ 2008-12-25
55
+ 2009-01-01
56
+ 2009-01-19
57
+ 2009-02-16
58
+ 2009-05-25
59
+ 2009-09-07
60
+ 2009-10-12
61
+ 2009-11-11
62
+ 2009-11-26
63
+ 2009-12-25
64
+ 2010-01-01
65
+ 2010-01-18
66
+ 2010-02-15
67
+ 2010-05-31
68
+ 2010-07-05
69
+ 2010-09-06
70
+ 2010-10-11
71
+ 2010-11-11
72
+ 2010-11-25
73
+ 2010-12-25
74
+ 2011-01-01
75
+ 2011-01-17
76
+ 2011-02-21
77
+ 2011-05-30
78
+ 2011-07-04
79
+ 2011-09-05
80
+ 2011-10-10
81
+ 2011-11-11
82
+ 2011-11-24
83
+ 2011-12-26
84
+ 2012-01-02
85
+ 2012-01-16
86
+ 2012-02-20
87
+ 2012-05-28
88
+ 2012-07-04
89
+ 2012-09-03
90
+ 2012-10-08
91
+ 2012-11-12
92
+ 2012-11-22
93
+ 2012-12-25
94
+ 2013-01-01
95
+ 2013-01-21
96
+ 2013-02-18
97
+ 2013-05-27
98
+ 2013-07-04
99
+ 2013-09-02
100
+ 2013-10-14
101
+ 2013-11-11
102
+ 2013-11-28
103
+ 2013-12-25
104
+ 2014-01-01
105
+ 2014-01-20
106
+ 2014-02-17
107
+ 2014-05-26
108
+ 2014-07-04
109
+ 2014-09-01
110
+ 2014-10-13
111
+ 2014-11-11
112
+ 2014-11-27
113
+ 2014-12-25
114
+ 2015-01-01
115
+ 2015-01-19
116
+ 2015-02-16
117
+ 2015-05-25
118
+ 2015-07-04
119
+ 2015-09-07
120
+ 2015-10-12
121
+ 2015-11-11
122
+ 2015-11-26
123
+ 2015-12-25
124
+ 2016-01-01
125
+ 2016-01-18
126
+ 2016-02-15
127
+ 2016-05-30
128
+ 2016-07-04
129
+ 2016-09-05
130
+ 2016-10-10
131
+ 2016-11-11
132
+ 2016-11-24
133
+ 2016-12-25
134
+ 2016-12-26
135
+ 2017-01-01
136
+ 2017-01-02
137
+ 2017-01-16
138
+ 2017-02-20
139
+ 2017-05-29
140
+ 2017-07-04
141
+ 2017-09-04
142
+ 2017-10-09
143
+ 2017-11-11
144
+ 2017-11-23
145
+ 2017-12-25
146
+ 2018-01-01
147
+ 2018-01-15
148
+ 2018-02-19
149
+ 2018-05-28
150
+ 2018-07-04
151
+ 2018-09-03
152
+ 2018-10-08
153
+ 2018-11-11
154
+ 2018-11-12
155
+ 2018-11-22
156
+ 2018-12-25
157
+ 2019-01-01
158
+ 2019-01-21
159
+ 2019-02-18
160
+ 2019-05-27
161
+ 2019-07-04
162
+ 2019-09-02
163
+ 2019-10-14
164
+ 2019-11-11
165
+ 2019-11-28
166
+ 2019-12-25
167
+ 2020-01-01
168
+ 2020-01-20
169
+ 2020-02-17
170
+ 2020-05-25
171
+ 2020-07-04
172
+ 2020-09-07
173
+ 2020-10-12
174
+ 2020-11-11
175
+ 2020-11-26
176
+ 2020-12-25
177
+ 2021-01-01
178
+ 2021-01-18
179
+ 2021-02-15
180
+ 2021-05-31
181
+ 2021-07-04
182
+ 2021-07-05
183
+ 2021-09-06
184
+ 2021-10-11
185
+ 2021-11-11
186
+ 2021-11-25
187
+ 2021-12-25
188
+ 2022-01-01
189
+ 2022-01-17
190
+ 2022-02-21
191
+ 2022-05-30
192
+ 2022-07-04
193
+ 2022-09-05
194
+ 2022-10-10
195
+ 2022-11-11
196
+ 2022-11-24
197
+ 2022-12-25
198
+ 2022-12-26
199
+ 2023-01-01
200
+ 2023-01-02
201
+ 2023-01-16
202
+ 2023-02-20
203
+ 2023-05-29
204
+ 2023-07-04
205
+ 2023-09-04
206
+ 2023-10-09
207
+ 2023-11-11
208
+ 2023-11-23
209
+ 2023-12-25
210
+ 2024-01-01
211
+ 2024-01-15
212
+ 2024-02-19
213
+ 2024-05-27
214
+ 2024-07-04
215
+ 2024-09-02
216
+ 2024-10-14
217
+ 2024-11-11
218
+ 2024-11-28
219
+ 2024-12-25
220
+ 2025-01-01
221
+ 2025-01-20
222
+ 2025-02-17
223
+ 2025-05-26
224
+ 2025-07-04
225
+ 2025-09-01
226
+ 2025-10-13
227
+ 2025-11-11
228
+ 2025-11-27
229
+ 2025-12-25
230
+ ).map { |x| Date.parse x }.each do |expected_holiday|
44
231
  it "treats #{expected_holiday} as a holiday" do
45
232
  expect(BusinessCalendar.for(:US).is_holiday?(expected_holiday)).to be true
46
233
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BusinessCalendar do
4
- before { Timecop.freeze('2014-04-28'.to_date) }
4
+ before { allow(Date).to receive(:today).and_return('2014-04-28'.to_date) }
5
5
  subject { BusinessCalendar.for(country) }
6
6
 
7
7
  shared_examples_for "standard business time" do
@@ -83,6 +83,10 @@ describe BusinessCalendar do
83
83
  specify "American Independence Day is not a business day" do
84
84
  expect(subject.is_business_day?('2014-07-04'.to_date)).to be false
85
85
  end
86
+
87
+ specify 'a time is converted to a date' do
88
+ expect(subject.is_holiday?(Time.parse('2014-07-04'))).to be true
89
+ end
86
90
  end
87
91
 
88
92
  context "in the UK" do
@@ -94,8 +98,8 @@ describe BusinessCalendar do
94
98
  expect(subject.is_business_day?('2014-07-04'.to_date)).to be true
95
99
  end
96
100
 
97
- specify 'Boxing Day is observed on a weekday' do
98
- expect(subject.is_business_day?('2015-12-28'.to_date)).to be false
101
+ specify 'Boxing Day is not observed on the next weekday' do
102
+ expect(subject.is_business_day?('2015-12-28'.to_date)).to be true
99
103
  end
100
104
  end
101
105
 
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
+ require 'simplecov'
5
+
4
6
  require 'business_calendar'
5
7
  require 'date'
6
- require 'timecop'
8
+ require 'pry'
9
+
7
10
 
8
11
  # I'm not depending on ActiveSupport just for this.
9
12
  class String
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
- prerelease:
4
+ version: 0.0.13
6
5
  platform: ruby
7
6
  authors:
8
7
  - Robert Nubel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: holidays
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,31 +48,27 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
- name: pry
56
+ name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ~>
68
60
  - !ruby/object:Gem::Version
69
- version: '0'
61
+ version: '3.2'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ~>
76
67
  - !ruby/object:Gem::Version
77
- version: '0'
68
+ version: '3.2'
78
69
  - !ruby/object:Gem::Dependency
79
- name: pry-debugger
70
+ name: simplecov
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,31 +76,13 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
- name: rspec
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: '3.2'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: '3.2'
110
- - !ruby/object:Gem::Dependency
111
- name: timecop
84
+ name: pry
112
85
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
86
  requirements:
115
87
  - - ! '>='
116
88
  - !ruby/object:Gem::Version
@@ -118,7 +90,6 @@ dependencies:
118
90
  type: :development
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
93
  requirements:
123
94
  - - ! '>='
124
95
  - !ruby/object:Gem::Version
@@ -133,15 +104,22 @@ extra_rdoc_files: []
133
104
  files:
134
105
  - .gitignore
135
106
  - .rspec
107
+ - .simplecov
108
+ - .travis.yml
136
109
  - Gemfile
137
110
  - LICENSE.txt
138
111
  - README.md
139
112
  - Rakefile
140
113
  - business_calendar.gemspec
141
- - data/holidays.yml
114
+ - data/BR.yml
115
+ - data/CN.yml
116
+ - data/GB.yml
117
+ - data/US.yml
118
+ - gemfiles/ree.gemfile
142
119
  - lib/business_calendar.rb
143
120
  - lib/business_calendar/calendar.rb
144
121
  - lib/business_calendar/holiday_determiner.rb
122
+ - lib/business_calendar/ruby18_shim.rb
145
123
  - lib/business_calendar/version.rb
146
124
  - spec/acceptance_br_spec.rb
147
125
  - spec/acceptance_cn_spec.rb
@@ -153,33 +131,26 @@ files:
153
131
  homepage: ''
154
132
  licenses:
155
133
  - MIT
134
+ metadata: {}
156
135
  post_install_message:
157
136
  rdoc_options: []
158
137
  require_paths:
159
138
  - lib
160
139
  required_ruby_version: !ruby/object:Gem::Requirement
161
- none: false
162
140
  requirements:
163
141
  - - ! '>='
164
142
  - !ruby/object:Gem::Version
165
143
  version: '0'
166
- segments:
167
- - 0
168
- hash: -788360373610172520
169
144
  required_rubygems_version: !ruby/object:Gem::Requirement
170
- none: false
171
145
  requirements:
172
146
  - - ! '>='
173
147
  - !ruby/object:Gem::Version
174
148
  version: '0'
175
- segments:
176
- - 0
177
- hash: -788360373610172520
178
149
  requirements: []
179
150
  rubyforge_project:
180
- rubygems_version: 1.8.23
151
+ rubygems_version: 2.4.5
181
152
  signing_key:
182
- specification_version: 3
153
+ specification_version: 4
183
154
  summary: Country-aware business-date logic and handling.
184
155
  test_files:
185
156
  - spec/acceptance_br_spec.rb