us_bank_holidays 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/README.md +9 -0
- data/lib/us_bank_holidays.rb +11 -4
- data/lib/us_bank_holidays/holiday_year.rb +2 -1
- data/lib/us_bank_holidays/version.rb +1 -1
- data/spec/functional/us_bank_holidays_spec.rb +36 -23
- data/spec/spec_helper.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b60841173b3f8f7871352347c1182b85a23dc144
|
4
|
+
data.tar.gz: 0aaa072931196f5f0f6a342efb0f4ae831280097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a523666e1a6f5b81383b8592c13de633e55a8101bbfc8e2fae9daa2acd651e172d2b45f6fa9897169394b6faed24de7ad3be0cea54118bbada2be319176a08f
|
7
|
+
data.tar.gz: c075e3c186c6420301a838125a6ba02cd993ac412ba269155ea42341450d6f00ca9f7d2d2fe68b5b8b6f457290f8c5ce5f097c9bbdb1c60fb0bf80961bf77e36
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@ https://github.com/albertosaurus/us_bank_holidays
|
|
4
4
|
|
5
5
|
[![Build Status](https://travis-ci.org/albertosaurus/us_bank_holidays.png?branch=master)](https://travis-ci.org/albertosaurus/us_bank_holidays)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/albertosaurus/us_bank_holidays.png)](https://codeclimate.com/github/albertosaurus/us_bank_holidays)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/us_bank_holidays.png)](http://badge.fury.io/rb/us_bank_holidays)
|
7
8
|
|
8
9
|
Patches `Date` to make working with US bank holidays easier
|
9
10
|
|
@@ -50,6 +51,14 @@ Date.new(2014, 1, 16).add_banking_days(2) # Returns Tuesday, January 21, 2014
|
|
50
51
|
Date.new(2014, 1, 5).previous_banking_day # Returns Friday, January 3, 2014
|
51
52
|
```
|
52
53
|
|
54
|
+
By default, weekends always count as bank holidays, but this can be disabled.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
date = Date.new(2014, 2, 2) # Sunday, February 2, 2014
|
58
|
+
date.bank_holiday? # Returns true
|
59
|
+
date.bank_holiday?(false) # Returns false
|
60
|
+
```
|
61
|
+
|
53
62
|
## Contributing
|
54
63
|
|
55
64
|
1. Fork it
|
data/lib/us_bank_holidays.rb
CHANGED
@@ -12,9 +12,14 @@ module UsBankHolidays
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# Returns true if the given date is a bank holiday, false otherwise.
|
15
|
-
|
16
|
-
|
15
|
+
# Pass the optional 'include_weekends' to control whether weekends should count as
|
16
|
+
# bank holidays (default is true).
|
17
|
+
def self.bank_holiday?(date, include_weekends = true)
|
18
|
+
if include_weekends && weekend?(date)
|
19
|
+
true
|
20
|
+
else
|
17
21
|
::UsBankHolidays::HolidayYear.new(date.year).bank_holidays.include?(date)
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
# Returns true if the given date is a banking day, i.e. is not a bank holiday,
|
@@ -48,8 +53,10 @@ module UsBankHolidays
|
|
48
53
|
end
|
49
54
|
|
50
55
|
# Returns true if the date is a bank holiday, false otherwise.
|
51
|
-
|
52
|
-
|
56
|
+
# Pass the optional 'include_weekends' to control whether weekends should count as
|
57
|
+
# bank holidays (default is true).
|
58
|
+
def bank_holiday?(include_weekends = true)
|
59
|
+
::UsBankHolidays.bank_holiday? self, include_weekends
|
53
60
|
end
|
54
61
|
|
55
62
|
# Returns the next banking day after this one.
|
@@ -88,19 +88,25 @@ describe UsBankHolidays do
|
|
88
88
|
|
89
89
|
describe '.bank_holiday?' do
|
90
90
|
it 'should determine bank holidays on the list' do
|
91
|
-
sample_holidays.each{ |holiday|
|
91
|
+
sample_holidays.each { |holiday|
|
92
92
|
UsBankHolidays.bank_holiday?(holiday).should be_true
|
93
93
|
UsBankHolidays.banking_day?(holiday).should be_false
|
94
94
|
}
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'weekends should be bank holidays' do
|
98
|
-
sample_weekends.each{ |weekend|
|
98
|
+
sample_weekends.each { |weekend|
|
99
99
|
UsBankHolidays.bank_holiday?(weekend).should be_true
|
100
100
|
UsBankHolidays.banking_day?(weekend).should be_false
|
101
101
|
}
|
102
102
|
end
|
103
103
|
|
104
|
+
it 'should exclude weekends if the appropriate flag is passed' do
|
105
|
+
sample_weekends.each { |weekend|
|
106
|
+
UsBankHolidays.bank_holiday?(weekend, false).should be_false
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
104
110
|
it 'regular days should not be bank holidays' do
|
105
111
|
sample_weekdays.each { |day|
|
106
112
|
UsBankHolidays.bank_holiday?(day).should be_false
|
@@ -111,7 +117,7 @@ describe UsBankHolidays do
|
|
111
117
|
|
112
118
|
describe '.weekend?' do
|
113
119
|
it 'should recognize weekends' do
|
114
|
-
sample_weekends.each{ |weekend|
|
120
|
+
sample_weekends.each { |weekend|
|
115
121
|
UsBankHolidays.weekend?(weekend).should be_true
|
116
122
|
UsBankHolidays.banking_day?(weekend).should be_false
|
117
123
|
}
|
@@ -124,47 +130,54 @@ describe UsBankHolidays do
|
|
124
130
|
|
125
131
|
describe ::UsBankHolidays::DateMethods do
|
126
132
|
|
127
|
-
describe '.
|
133
|
+
describe '.weekend?' do
|
128
134
|
|
129
|
-
it 'should recognize
|
130
|
-
|
131
|
-
|
132
|
-
|
135
|
+
it 'should recognize weekends' do
|
136
|
+
sample_weekends.each { |weekend|
|
137
|
+
weekend.weekend?.should be_true
|
138
|
+
weekend.banking_day?.should be_false
|
133
139
|
}
|
134
140
|
end
|
135
141
|
|
136
|
-
it 'should
|
137
|
-
sample_weekends.each{ |weekend| weekend.bank_holiday?.should be_true }
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should not treat regular weekdays as bank holidays' do
|
142
|
+
it 'weekdays should not be considered weekends' do
|
141
143
|
sample_weekdays.each { |day|
|
142
|
-
day.
|
144
|
+
day.weekend?.should be_false
|
143
145
|
day.banking_day?.should be_true
|
144
146
|
}
|
145
147
|
end
|
146
148
|
|
147
|
-
it 'if Jan. 1 falls on a Saturday, Dec. 31 of the previous year should be a bank holiday' do
|
148
|
-
Date.new(2021, 12, 31).bank_holiday?.should be_true
|
149
|
-
end
|
150
149
|
end
|
151
150
|
|
152
|
-
describe '.
|
151
|
+
describe '.bank_holiday?' do
|
153
152
|
|
154
|
-
it 'should recognize
|
155
|
-
|
153
|
+
it 'should recognize bank holidays' do
|
154
|
+
sample_holidays.each { |holiday|
|
155
|
+
holiday.bank_holiday?.should be_true
|
156
|
+
holiday.banking_day?.should be_false
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should treat weekends as bank holidays' do
|
161
|
+
sample_weekends.each { |weekend| weekend.bank_holiday?.should be_true }
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should exclude weekends if the appropriate flag is passed' do
|
165
|
+
sample_weekends.each { |weekend|
|
156
166
|
weekend.weekend?.should be_true
|
157
|
-
weekend.
|
167
|
+
weekend.bank_holiday?(false).should be_false
|
158
168
|
}
|
159
169
|
end
|
160
170
|
|
161
|
-
it '
|
171
|
+
it 'should not treat regular weekdays as bank holidays' do
|
162
172
|
sample_weekdays.each { |day|
|
163
|
-
day.
|
173
|
+
day.bank_holiday?.should be_false
|
164
174
|
day.banking_day?.should be_true
|
165
175
|
}
|
166
176
|
end
|
167
177
|
|
178
|
+
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
|
180
|
+
end
|
168
181
|
end
|
169
182
|
|
170
183
|
describe '.next_banking_day' do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,9 @@ unless ENV['TRAVIS']
|
|
3
3
|
SimpleCov.start
|
4
4
|
end
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'bundler/setup'
|
7
|
+
|
8
|
+
require 'us_bank_holidays'
|
7
9
|
|
8
10
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
9
11
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: us_bank_holidays
|
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
|
- Arthur Shagall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.1.11
|
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.
|