business_calendar 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/holidays.yml +65 -2
- data/lib/business_calendar/holiday_determiner.rb +5 -4
- data/lib/business_calendar/version.rb +1 -1
- data/lib/business_calendar.rb +3 -2
- data/spec/acceptance_cn_spec.rb +64 -0
- data/spec/business_calendar/holiday_determiner_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3765778a8cc3a3cb82811a0ce743c5a233e3b26f
|
4
|
+
data.tar.gz: 46ca23d3b70e419ba006951b6a7251bbc59edcd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25d0fb29fdec3795c121315e0a03e7b9978ce7abeabc60c0e185865a1da8da52f481e21debf15701da34ef59c108a598c037b56443859d2e7531b3d46c8dc05c
|
7
|
+
data.tar.gz: 297589d9331d61849b413679ad6aeff8fa874efb7c57a44227f6f5358a54fc175c8553ce50a4044d2fcef7c4a9112bb50d9f7363329d366c9ede093cbe2353dd
|
data/data/holidays.yml
CHANGED
@@ -1,3 +1,8 @@
|
|
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 +addtions+ here. Useful e.g. for cases where a
|
3
|
+
# country is not even defined in the `holidays` gem.
|
4
|
+
# Defaults to `false`
|
5
|
+
|
1
6
|
US:
|
2
7
|
regions:
|
3
8
|
- 'us'
|
@@ -33,6 +38,64 @@ GB:
|
|
33
38
|
- '2002-05-28'
|
34
39
|
- '2012-05-28'
|
35
40
|
|
41
|
+
# TODO: Add CN capability and holidays to holidays gem
|
36
42
|
CN:
|
37
|
-
regions:
|
38
|
-
|
43
|
+
regions:
|
44
|
+
- 'cn'
|
45
|
+
additions:
|
46
|
+
- '2014-01-01'
|
47
|
+
- '2014-01-31'
|
48
|
+
- '2014-02-01'
|
49
|
+
- '2014-02-02'
|
50
|
+
- '2014-02-03'
|
51
|
+
- '2014-02-04'
|
52
|
+
- '2014-02-05'
|
53
|
+
- '2014-02-06'
|
54
|
+
- '2014-04-05'
|
55
|
+
- '2014-04-06'
|
56
|
+
- '2014-04-07'
|
57
|
+
- '2014-05-01'
|
58
|
+
- '2014-05-02'
|
59
|
+
- '2014-05-03'
|
60
|
+
- '2014-05-31'
|
61
|
+
- '2014-06-01'
|
62
|
+
- '2014-06-02'
|
63
|
+
- '2014-09-06'
|
64
|
+
- '2014-09-07'
|
65
|
+
- '2014-09-08'
|
66
|
+
- '2014-10-01'
|
67
|
+
- '2014-10-02'
|
68
|
+
- '2014-10-03'
|
69
|
+
- '2014-10-04'
|
70
|
+
- '2014-10-05'
|
71
|
+
- '2014-10-06'
|
72
|
+
- '2014-10-07'
|
73
|
+
- '2015-01-01'
|
74
|
+
- '2015-02-19'
|
75
|
+
- '2015-02-20'
|
76
|
+
- '2015-02-21'
|
77
|
+
- '2015-02-22'
|
78
|
+
- '2015-02-23'
|
79
|
+
- '2015-02-24'
|
80
|
+
- '2015-02-25'
|
81
|
+
- '2015-04-05'
|
82
|
+
- '2015-04-06'
|
83
|
+
- '2015-04-07'
|
84
|
+
- '2015-05-01'
|
85
|
+
- '2015-05-02'
|
86
|
+
- '2015-05-03'
|
87
|
+
- '2015-06-20'
|
88
|
+
- '2015-06-21'
|
89
|
+
- '2015-06-22'
|
90
|
+
- '2015-09-27'
|
91
|
+
- '2015-09-28'
|
92
|
+
- '2015-09-29'
|
93
|
+
- '2015-10-01'
|
94
|
+
- '2015-10-02'
|
95
|
+
- '2015-10-03'
|
96
|
+
- '2015-10-04'
|
97
|
+
- '2015-10-05'
|
98
|
+
- '2015-10-06'
|
99
|
+
- '2015-10-07'
|
100
|
+
additions_only: true
|
101
|
+
holiday_names: [] # Not needed cause all holidays are via manual +additions+
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'holidays'
|
2
2
|
|
3
3
|
class BusinessCalendar::HolidayDeterminer
|
4
|
-
attr_reader :regions, :holiday_names, :additions, :removals
|
4
|
+
attr_reader :regions, :holiday_names, :additions, :removals, :additions_only
|
5
5
|
|
6
6
|
def initialize(regions, holiday_names, opts = {})
|
7
7
|
@regions = regions
|
8
8
|
@holiday_names = holiday_names
|
9
|
-
@additions = opts[:additions]
|
10
|
-
@removals = opts[:removals]
|
9
|
+
@additions = opts[:additions] || []
|
10
|
+
@removals = opts[:removals] || []
|
11
|
+
@additions_only = opts[:additions_only] || false
|
11
12
|
end
|
12
13
|
|
13
14
|
def call(date)
|
@@ -15,7 +16,7 @@ class BusinessCalendar::HolidayDeterminer
|
|
15
16
|
true
|
16
17
|
elsif removals.include? date
|
17
18
|
false
|
18
|
-
|
19
|
+
elsif !additions_only
|
19
20
|
Holidays.between(date, date, @regions, :observed)
|
20
21
|
.select { |h| @holiday_names.include? h[:name] }
|
21
22
|
.size > 0
|
data/lib/business_calendar.rb
CHANGED
@@ -12,8 +12,9 @@ module BusinessCalendar
|
|
12
12
|
@holiday_procs[country] ||= HolidayDeterminer.new(
|
13
13
|
cfg["regions"],
|
14
14
|
cfg["holiday_names"],
|
15
|
-
:additions
|
16
|
-
:removals
|
15
|
+
:additions => (cfg["additions"] || []).map { |s| Date.parse s },
|
16
|
+
:removals => (cfg["removals"] || []).map { |s| Date.parse s },
|
17
|
+
:additions_only => cfg['additions_only'] )
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.config(country)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "CN holidays" do
|
4
|
+
%w(
|
5
|
+
2014-01-01
|
6
|
+
2014-01-31
|
7
|
+
2014-02-01
|
8
|
+
2014-02-02
|
9
|
+
2014-02-03
|
10
|
+
2014-02-04
|
11
|
+
2014-02-05
|
12
|
+
2014-02-06
|
13
|
+
2014-04-05
|
14
|
+
2014-04-06
|
15
|
+
2014-04-07
|
16
|
+
2014-05-01
|
17
|
+
2014-05-02
|
18
|
+
2014-05-03
|
19
|
+
2014-05-31
|
20
|
+
2014-06-01
|
21
|
+
2014-06-02
|
22
|
+
2014-09-06
|
23
|
+
2014-09-07
|
24
|
+
2014-09-08
|
25
|
+
2014-10-01
|
26
|
+
2014-10-02
|
27
|
+
2014-10-03
|
28
|
+
2014-10-04
|
29
|
+
2014-10-05
|
30
|
+
2014-10-06
|
31
|
+
2014-10-07
|
32
|
+
2015-01-01
|
33
|
+
2015-02-19
|
34
|
+
2015-02-20
|
35
|
+
2015-02-21
|
36
|
+
2015-02-22
|
37
|
+
2015-02-23
|
38
|
+
2015-02-24
|
39
|
+
2015-02-25
|
40
|
+
2015-04-05
|
41
|
+
2015-04-06
|
42
|
+
2015-04-07
|
43
|
+
2015-05-01
|
44
|
+
2015-05-02
|
45
|
+
2015-05-03
|
46
|
+
2015-06-20
|
47
|
+
2015-06-21
|
48
|
+
2015-06-22
|
49
|
+
2015-09-27
|
50
|
+
2015-09-28
|
51
|
+
2015-09-29
|
52
|
+
2015-10-01
|
53
|
+
2015-10-02
|
54
|
+
2015-10-03
|
55
|
+
2015-10-04
|
56
|
+
2015-10-05
|
57
|
+
2015-10-06
|
58
|
+
2015-10-07
|
59
|
+
).map { |x| Date.parse x }.each do |expected_holiday|
|
60
|
+
it "treats #{expected_holiday} as a holiday" do
|
61
|
+
BusinessCalendar.for(:CN).is_holiday?(expected_holiday).should be_true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -33,4 +33,19 @@ describe BusinessCalendar::HolidayDeterminer do
|
|
33
33
|
subject.call('2101-07-05'.to_date).should be_true
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
context "with a list of additions and additions_only set to true" do
|
38
|
+
let(:opts) {{
|
39
|
+
:additions => ['2101-07-05'.to_date],
|
40
|
+
:additions_only => true
|
41
|
+
}}
|
42
|
+
|
43
|
+
it "correctly determines true for the additions" do
|
44
|
+
subject.call('2101-07-05'.to_date).should be_true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "correctly determines false for dates not in additions, nor exceptions" do
|
48
|
+
subject.call('2101-07-04'.to_date).should be_false
|
49
|
+
end
|
50
|
+
end
|
36
51
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Nubel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: holidays
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/business_calendar/calendar.rb
|
101
101
|
- lib/business_calendar/holiday_determiner.rb
|
102
102
|
- lib/business_calendar/version.rb
|
103
|
+
- spec/acceptance_cn_spec.rb
|
103
104
|
- spec/acceptance_gb_spec.rb
|
104
105
|
- spec/acceptance_us_spec.rb
|
105
106
|
- spec/business_calendar/holiday_determiner_spec.rb
|
@@ -130,6 +131,7 @@ signing_key:
|
|
130
131
|
specification_version: 4
|
131
132
|
summary: Country-aware business-date logic and handling.
|
132
133
|
test_files:
|
134
|
+
- spec/acceptance_cn_spec.rb
|
133
135
|
- spec/acceptance_gb_spec.rb
|
134
136
|
- spec/acceptance_us_spec.rb
|
135
137
|
- spec/business_calendar/holiday_determiner_spec.rb
|