us_bank_holidays 0.0.6 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ee3cf09af1f0d5b0b2379476f041fb77b11359e
4
- data.tar.gz: 8d5c8f34faea3644b419f6648a267646436d3bfc
3
+ metadata.gz: d44603e174d94f3058f71f7bdf030e762c350f78
4
+ data.tar.gz: b8ad012d2c75fd2b29270980bfa0e53dd0de04d3
5
5
  SHA512:
6
- metadata.gz: 71fe95c8e28a99f36cbd69987b13e01e23c4f3e7b45e4091cb768459cf1ac073b8a728ca92416921c44ac17495ea9c24f606216d3fa8db105d44d5cb3c4f0238
7
- data.tar.gz: cb80c0d4fe13b5a6e216d714e8c62f8fb9c0a2d05a75bf6749f5403fee39f600fde26d4bf14fde2b038dc4f80a1a7ea8e48e97d8b0f417a7520aaace032b8390
6
+ metadata.gz: 90647b055da3c2ee6c1e2853e2c4ae0b6f054034421b7ad051154383b792408c0dec52969f899d37237b3826002ae3573ad227930e95f2161596e4e8d6636c63
7
+ data.tar.gz: 3a63bd609a2f63b53f030a495a4030ac40d752a87b81dd94a4d4567c349be4157b635a71fb06739280e13e55ec896f207ce330d5af3e2ff8caaf39c7a672287b
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  script: 'bundle exec rake spec'
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3
7
8
  - jruby
8
9
  - rbx
9
10
  matrix:
@@ -14,6 +14,8 @@ module UsBankHolidays
14
14
  # Returns true if the given date is a bank holiday, false otherwise.
15
15
  # Pass the optional 'include_weekends' to control whether weekends should count as
16
16
  # bank holidays (default is true).
17
+ # If include_weekends is set to false but the date is a Federal bank holiday,
18
+ # returns true (Ex: 4th of July, 2015, Christmas Day 2016)
17
19
  def self.bank_holiday?(date, include_weekends = true)
18
20
  if include_weekends && weekend?(date)
19
21
  true
@@ -44,6 +46,12 @@ module UsBankHolidays
44
46
  end
45
47
  end
46
48
 
49
+ # If enabled (ENV["NO_FRIDAY_HOLIDAY_ACH"]), a Friday that falls a day before
50
+ # a Saturday that's a bank holiday is considered a bank holiday
51
+ def self.saturday_holiday_date_rolling?
52
+ !!ENV["NO_FRIDAY_HOLIDAY_ACH"]
53
+ end
54
+
47
55
  # Instance methods to be injected into the Date class
48
56
  module DateMethods
49
57
 
@@ -55,6 +63,8 @@ module UsBankHolidays
55
63
  # Returns true if the date is a bank holiday, false otherwise.
56
64
  # Pass the optional 'include_weekends' to control whether weekends should count as
57
65
  # bank holidays (default is true).
66
+ # If include_weekends is set to false but the date is a Federal bank holiday,
67
+ # returns true (Ex: 4th of July, 2015, Christmas Day 2016)
58
68
  def bank_holiday?(include_weekends = true)
59
69
  ::UsBankHolidays.bank_holiday? self, include_weekends
60
70
  end
@@ -26,8 +26,7 @@ module UsBankHolidays
26
26
  end
27
27
 
28
28
  # Returns the federal holidays for the given year on the dates they will actually
29
- # be observed. In the event that New Year's Day for the following year falls on a
30
- # Saturday December 31 will also be included.
29
+ # be observed.
31
30
  def bank_holidays
32
31
  @bank_holidays ||= begin
33
32
  holidays = [ new_years_day,
@@ -107,11 +106,12 @@ module UsBankHolidays
107
106
  @christmas = roll_nominal(Date.new(year, 12, 25))
108
107
  end
109
108
 
110
- # Figures out where to roll the given nominal date. If it's a Saturday, assumes
111
- # it's the day before (Friday), if Sunday it's the date after (Monday), otherwise
109
+ # Figures out where to roll the given nominal date. If it's a Saturday and
110
+ # Saturday holiday date rolling is enabled (see UsBankHolidays#saturday_holiday_date_rolling?),
111
+ # assumes it's the day before (Friday), if Sunday it's the date after (Monday), otherwise
112
112
  # just returns self.
113
113
  def roll_nominal(nominal)
114
- if nominal.saturday?
114
+ if nominal.saturday? && ::UsBankHolidays.saturday_holiday_date_rolling?
115
115
  nominal - 1
116
116
  elsif nominal.sunday?
117
117
  nominal + 1
@@ -1,3 +1,3 @@
1
1
  module UsBankHolidays
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,19 +2,51 @@ require 'spec_helper'
2
2
 
3
3
  describe UsBankHolidays::HolidayYear do
4
4
 
5
- it 'should determine bank holidays' do
6
- UsBankHolidays::HolidayYear.new(2017).bank_holidays.should == [
7
- '2017-01-02', #New Year’s Day
8
- '2017-01-16', #Birthday of Martin Luther King, Jr.
9
- '2017-02-20', #Washington’s Birthday
10
- '2017-05-29', #Memorial Day
11
- '2017-07-04', #Independence Day
12
- '2017-09-04', #Labor Day
13
- '2017-10-09', #Columbus Day
14
- '2017-11-10', #Veterans Day
15
- '2017-11-23', #Thanksgiving Day
16
- '2017-12-25' #Christmas Day
17
- ].map{|d| Date.parse(d) }
5
+ context "should determine bank holidays" do
6
+
7
+ context "Force Saturday date rolling" do
8
+ before :each do
9
+ allow(::UsBankHolidays).to receive(:saturday_holiday_date_rolling?).and_return(true)
10
+ end
11
+
12
+ it 'should determine bank holidays' do
13
+ expect(UsBankHolidays::HolidayYear.new(2017).bank_holidays).to eq([
14
+ '2017-01-02', #New Year’s Day
15
+ '2017-01-16', #Birthday of Martin Luther King, Jr.
16
+ '2017-02-20', #Washington’s Birthday
17
+ '2017-05-29', #Memorial Day
18
+ '2017-07-04', #Independence Day
19
+ '2017-09-04', #Labor Day
20
+ '2017-10-09', #Columbus Day
21
+ '2017-11-10', #Veterans Day
22
+ '2017-11-23', #Thanksgiving Day
23
+ '2017-12-25' #Christmas Day
24
+ ].map {|d| Date.parse(d)}
25
+ )
26
+ end
27
+
28
+ end
29
+
30
+ context "No Saturday date rolling" do
31
+ it 'should determine bank holidays' do
32
+ expect(UsBankHolidays::HolidayYear.new(2017).bank_holidays).to eq([
33
+ '2017-01-02', #New Year’s Day
34
+ '2017-01-16', #Birthday of Martin Luther King, Jr.
35
+ '2017-02-20', #Washington’s Birthday
36
+ '2017-05-29', #Memorial Day
37
+ '2017-07-04', #Independence Day
38
+ '2017-09-04', #Labor Day
39
+ '2017-10-09', #Columbus Day
40
+ '2017-11-11', #Veterans Day
41
+ '2017-11-23', #Thanksgiving Day
42
+ '2017-12-25' #Christmas Day
43
+ ].map {|d| Date.parse(d)}
44
+ )
45
+ end
46
+
47
+ end
48
+
49
+
18
50
  end
19
51
 
20
52
  it 'should declare Dec. 31 a bank holiday if it falls on a Friday' do
@@ -39,7 +71,7 @@ describe UsBankHolidays::HolidayYear do
39
71
  :december => 12
40
72
  }.each do |month_name, month_index|
41
73
  it "should respond to '#{month_name}' and return the right month" do
42
- year.respond_to?(month_name).should be_true
74
+ expect(year.respond_to?(month_name)).to eq(true)
43
75
  month = year.send(month_name)
44
76
  month.year.should == 2014
45
77
  month.month.should == month_index
@@ -23,19 +23,19 @@ describe UsBankHolidays::Month do
23
23
 
24
24
  it 'should return true if the month contains the given date' do
25
25
  (1..31).each do |mday|
26
- january.contains?(Date.new(january.year, january.month, mday)).should be_true
26
+ january.contains?(Date.new(january.year, january.month, mday)).should eq(true)
27
27
  end
28
28
  end
29
29
 
30
30
  it 'should return false if the month is not the same' do
31
31
  (1..31).each do |mday|
32
- january.contains?(Date.new(2014, 8, mday)).should be_false
32
+ january.contains?(Date.new(2014, 8, mday)).should eq(false)
33
33
  end
34
34
  end
35
35
 
36
36
  it 'should return false if the year is not the same' do
37
37
  (1..31).each do |mday|
38
- january.contains?(Date.new(2015, 1, mday)).should be_false
38
+ january.contains?(Date.new(2015, 1, mday)).should eq(false)
39
39
  end
40
40
  end
41
41
  end
@@ -113,4 +113,4 @@ Su Mo Tu We Th Fr Sa
113
113
 
114
114
  end
115
115
  end
116
- end
116
+ end
@@ -86,31 +86,35 @@ describe UsBankHolidays do
86
86
 
87
87
  let(:sample_weekdays) { [3, 4, 5, 6, 7].map{|d| Date.new(2014, 2, d) } }
88
88
 
89
+ before :each do
90
+ allow(::UsBankHolidays).to receive(:saturday_holiday_date_rolling?).and_return(true)
91
+ end
92
+
89
93
  describe '.bank_holiday?' do
90
94
  it 'should determine bank holidays on the list' do
91
95
  sample_holidays.each { |holiday|
92
- UsBankHolidays.bank_holiday?(holiday).should be_true
93
- UsBankHolidays.banking_day?(holiday).should be_false
96
+ UsBankHolidays.bank_holiday?(holiday).should eq(true)
97
+ UsBankHolidays.banking_day?(holiday).should eq(false)
94
98
  }
95
99
  end
96
100
 
97
101
  it 'weekends should be bank holidays' do
98
102
  sample_weekends.each { |weekend|
99
- UsBankHolidays.bank_holiday?(weekend).should be_true
100
- UsBankHolidays.banking_day?(weekend).should be_false
103
+ UsBankHolidays.bank_holiday?(weekend).should eq(true)
104
+ UsBankHolidays.banking_day?(weekend).should eq(false)
101
105
  }
102
106
  end
103
107
 
104
108
  it 'should exclude weekends if the appropriate flag is passed' do
105
109
  sample_weekends.each { |weekend|
106
- UsBankHolidays.bank_holiday?(weekend, false).should be_false
110
+ UsBankHolidays.bank_holiday?(weekend, false).should eq(false)
107
111
  }
108
112
  end
109
113
 
110
114
  it 'regular days should not be bank holidays' do
111
115
  sample_weekdays.each { |day|
112
- UsBankHolidays.bank_holiday?(day).should be_false
113
- UsBankHolidays.banking_day?(day).should be_true
116
+ UsBankHolidays.bank_holiday?(day).should eq(false)
117
+ UsBankHolidays.banking_day?(day).should eq(true)
114
118
  }
115
119
  end
116
120
  end
@@ -118,13 +122,13 @@ describe UsBankHolidays do
118
122
  describe '.weekend?' do
119
123
  it 'should recognize weekends' do
120
124
  sample_weekends.each { |weekend|
121
- UsBankHolidays.weekend?(weekend).should be_true
122
- UsBankHolidays.banking_day?(weekend).should be_false
125
+ UsBankHolidays.weekend?(weekend).should eq(true)
126
+ UsBankHolidays.banking_day?(weekend).should eq(false)
123
127
  }
124
128
  end
125
129
 
126
130
  it 'weekdays should not be considered weekends' do
127
- sample_weekdays.each { |day| UsBankHolidays.weekend?(day).should be_false }
131
+ sample_weekdays.each { |day| UsBankHolidays.weekend?(day).should eq(false) }
128
132
  end
129
133
  end
130
134
 
@@ -134,15 +138,15 @@ describe UsBankHolidays do
134
138
 
135
139
  it 'should recognize weekends' do
136
140
  sample_weekends.each { |weekend|
137
- weekend.weekend?.should be_true
138
- weekend.banking_day?.should be_false
141
+ weekend.weekend?.should eq(true)
142
+ weekend.banking_day?.should eq(false)
139
143
  }
140
144
  end
141
145
 
142
146
  it 'weekdays should not be considered weekends' do
143
147
  sample_weekdays.each { |day|
144
- day.weekend?.should be_false
145
- day.banking_day?.should be_true
148
+ day.weekend?.should eq(false)
149
+ day.banking_day?.should eq(true)
146
150
  }
147
151
  end
148
152
 
@@ -152,31 +156,31 @@ describe UsBankHolidays do
152
156
 
153
157
  it 'should recognize bank holidays' do
154
158
  sample_holidays.each { |holiday|
155
- holiday.bank_holiday?.should be_true
156
- holiday.banking_day?.should be_false
159
+ holiday.bank_holiday?.should eq(true)
160
+ holiday.banking_day?.should eq(false)
157
161
  }
158
162
  end
159
163
 
160
164
  it 'should treat weekends as bank holidays' do
161
- sample_weekends.each { |weekend| weekend.bank_holiday?.should be_true }
165
+ sample_weekends.each { |weekend| weekend.bank_holiday?.should eq(true) }
162
166
  end
163
167
 
164
168
  it 'should exclude weekends if the appropriate flag is passed' do
165
169
  sample_weekends.each { |weekend|
166
- weekend.weekend?.should be_true
167
- weekend.bank_holiday?(false).should be_false
170
+ weekend.weekend?.should eq(true)
171
+ weekend.bank_holiday?(false).should eq(false)
168
172
  }
169
173
  end
170
174
 
171
175
  it 'should not treat regular weekdays as bank holidays' do
172
176
  sample_weekdays.each { |day|
173
- day.bank_holiday?.should be_false
174
- day.banking_day?.should be_true
177
+ day.bank_holiday?.should eq(false)
178
+ day.banking_day?.should eq(true)
175
179
  }
176
180
  end
177
181
 
178
182
  it 'if Jan. 1 falls on a Saturday, Dec. 31 of the previous year should be a bank holiday' do
179
- Date.new(2021, 12, 31).bank_holiday?.should be_true
183
+ Date.new(2021, 12, 31).bank_holiday?.should eq(true)
180
184
  end
181
185
  end
182
186
 
@@ -220,21 +224,21 @@ describe UsBankHolidays do
220
224
 
221
225
  describe '.last_banking_day_of_month?' do
222
226
  it 'should determine if a date is the last banking day of the month' do
223
- Date.new(2014, 1, 31).last_banking_day_of_month?.should be_true
224
- Date.new(2014, 1, 30).last_banking_day_of_month?.should be_false
227
+ Date.new(2014, 1, 31).last_banking_day_of_month?.should eq(true)
228
+ Date.new(2014, 1, 30).last_banking_day_of_month?.should eq(false)
225
229
 
226
- Date.new(2014, 11, 30).last_banking_day_of_month?.should be_false
227
- Date.new(2014, 11, 28).last_banking_day_of_month?.should be_true
230
+ Date.new(2014, 11, 30).last_banking_day_of_month?.should eq(false)
231
+ Date.new(2014, 11, 28).last_banking_day_of_month?.should eq(true)
228
232
  end
229
233
  end
230
234
 
231
235
  describe '.first_banking_day_of_month?' do
232
236
  it 'should determine if the date if the first banking day of the month' do
233
- Date.new(2014, 4, 1).first_banking_day_of_month?.should be_true
234
- Date.new(2014, 4, 2).first_banking_day_of_month?.should be_false
237
+ Date.new(2014, 4, 1).first_banking_day_of_month?.should eq(true)
238
+ Date.new(2014, 4, 2).first_banking_day_of_month?.should eq(false)
235
239
 
236
- Date.new(2014, 6, 1).first_banking_day_of_month?.should be_false
237
- Date.new(2014, 6, 2).first_banking_day_of_month?.should be_true
240
+ Date.new(2014, 6, 1).first_banking_day_of_month?.should eq(false)
241
+ Date.new(2014, 6, 2).first_banking_day_of_month?.should eq(true)
238
242
  end
239
243
  end
240
244
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: us_bank_holidays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Shagall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-01 00:00:00.000000000 Z
11
+ date: 2017-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
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
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
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
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '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
68
  version: '0'
69
69
  description: Simplify working with US bank holidays.
@@ -73,7 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .travis.yml
76
+ - ".travis.yml"
77
77
  - Gemfile
78
78
  - LICENSE.txt
79
79
  - README.md
@@ -97,17 +97,17 @@ require_paths:
97
97
  - lib
98
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - '>='
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.1.11
110
+ rubygems_version: 2.6.8
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Patches Date to add methods to make dealing with US bank holidays simpler.