us_bank_holidays 0.0.1 → 0.0.2
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 +4 -4
- data/.travis.yml +11 -0
- data/README.md +15 -1
- data/lib/us_bank_holidays/holiday_year.rb +17 -10
- data/lib/us_bank_holidays/version.rb +1 -1
- data/lib/us_bank_holidays.rb +22 -0
- data/spec/functional/us_bank_holidays_spec.rb +32 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 421d85478436ebcc1574e2ccc9639b887029e46e
|
4
|
+
data.tar.gz: 3a0cd71dd007bfddc392a016739eabcae93af9c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a919b687012cc56dea4f7afa1259715b83e037ac275e236dda25f1ebfd9fd9de6e642d3f8ad89f03e5cfc46846b46a84f95c16e84f96d78489daf0cd4a48cd
|
7
|
+
data.tar.gz: 18552331c1658fdc6a1eda5db1bdfe61485c6736a5ae318064fadeb48a45fc6304ca625c6c5c810ec2e612cb46b21a6043160d5b0012fa72e72ffce041748e82
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
# UsBankHolidays
|
2
2
|
|
3
|
+
https://github.com/albertosaurus/us_bank_holidays
|
4
|
+
|
5
|
+
[](https://travis-ci.org/albertosaurus/us_bank_holidays)
|
6
|
+
|
3
7
|
Patches `Date` to make working with US bank holidays easier
|
4
8
|
|
9
|
+
## Requirements
|
10
|
+
|
11
|
+
Tested against the following Ruby runtimes:
|
12
|
+
|
13
|
+
* MRI 1.9.3, 2.0.0, 2.1.0
|
14
|
+
* JRuby 1.7+
|
15
|
+
* Rubinius (latest)
|
16
|
+
|
5
17
|
## Installation
|
6
18
|
|
7
19
|
Add this line to your application's Gemfile:
|
@@ -10,7 +22,7 @@ Add this line to your application's Gemfile:
|
|
10
22
|
|
11
23
|
And then execute:
|
12
24
|
|
13
|
-
$ bundle
|
25
|
+
$ bundle install
|
14
26
|
|
15
27
|
Or install it yourself as:
|
16
28
|
|
@@ -31,8 +43,10 @@ date = Date.new(2014, 1, 3) # Friday, January 3, 2014
|
|
31
43
|
date.bank_holiday? # Returns false
|
32
44
|
date.weekend? # Returns false
|
33
45
|
date.next_banking_day # Returns Monday, January 6, 2014
|
46
|
+
date.banking_day? # Returns true
|
34
47
|
|
35
48
|
Date.new(2014, 1, 16).add_banking_days(2) # Returns Tuesday, January 21, 2014
|
49
|
+
Date.new(2014, 1, 5).previous_banking_day # Returns Friday, January 3, 2014
|
36
50
|
```
|
37
51
|
|
38
52
|
## Contributing
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module UsBankHolidays
|
2
2
|
|
3
|
+
# Utility class to calculate where the federal holidays will actually fall
|
4
|
+
# for any given year.
|
3
5
|
class HolidayYear
|
4
6
|
|
5
7
|
attr_reader :year,
|
@@ -49,6 +51,9 @@ module UsBankHolidays
|
|
49
51
|
|
50
52
|
end
|
51
53
|
|
54
|
+
# Returns the federal holidays for the given year on the dates they will actually
|
55
|
+
# be observed. In the event that New Year's Day for the following year falls on a
|
56
|
+
# Saturday December 31 will also be included.
|
52
57
|
def bank_holidays
|
53
58
|
@bank_holidays ||= begin
|
54
59
|
holidays = [ new_years_day,
|
@@ -69,17 +74,19 @@ module UsBankHolidays
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
# Figures out where to roll the given nominal date. If it's a Saturday, assumes
|
78
|
+
# it's the day before (Friday), if Sunday it's the date after (Monday), otherwise
|
79
|
+
# just returns self.
|
80
|
+
def roll_nominal(nominal)
|
81
|
+
if nominal.saturday?
|
82
|
+
nominal - 1
|
83
|
+
elsif nominal.sunday?
|
84
|
+
nominal + 1
|
85
|
+
else
|
86
|
+
nominal
|
82
87
|
end
|
88
|
+
end
|
89
|
+
private :roll_nominal
|
83
90
|
|
84
91
|
end
|
85
92
|
|
data/lib/us_bank_holidays.rb
CHANGED
@@ -6,15 +6,23 @@ require 'us_bank_holidays/month'
|
|
6
6
|
|
7
7
|
module UsBankHolidays
|
8
8
|
|
9
|
+
# Returns true if the given date is a weekend, false otherwise.
|
9
10
|
def self.weekend?(date)
|
10
11
|
date.sunday? || date.saturday?
|
11
12
|
end
|
12
13
|
|
14
|
+
# Returns true if the given date is a bank holiday, false otherwise.
|
13
15
|
def self.bank_holiday?(date)
|
14
16
|
weekend?(date) ||
|
15
17
|
::UsBankHolidays::HolidayYear.new(date.year).bank_holidays.include?(date)
|
16
18
|
end
|
17
19
|
|
20
|
+
# Returns true if the given date is a banking day, i.e. is not a bank holiday,
|
21
|
+
# false otherwise.
|
22
|
+
def self.banking_day?(date)
|
23
|
+
!bank_holiday?(date)
|
24
|
+
end
|
25
|
+
|
18
26
|
def self.next_banking_day(date)
|
19
27
|
if (next_date = date + 1).bank_holiday?
|
20
28
|
next_banking_day(next_date)
|
@@ -31,24 +39,32 @@ module UsBankHolidays
|
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
42
|
+
# Instance methods to be injected into the Date class
|
34
43
|
module DateMethods
|
35
44
|
|
45
|
+
# Returns true if the date if a weekend, false otherwise.
|
36
46
|
def weekend?
|
37
47
|
::UsBankHolidays.weekend? self
|
38
48
|
end
|
39
49
|
|
50
|
+
# Returns true if the date is a bank holiday, false otherwise.
|
40
51
|
def bank_holiday?
|
41
52
|
::UsBankHolidays.bank_holiday? self
|
42
53
|
end
|
43
54
|
|
55
|
+
# Returns the next banking day after this one.
|
44
56
|
def next_banking_day
|
45
57
|
::UsBankHolidays.next_banking_day self
|
46
58
|
end
|
47
59
|
|
60
|
+
# Returns the previous banking day
|
48
61
|
def previous_banking_day
|
49
62
|
::UsBankHolidays.previous_banking_day self
|
50
63
|
end
|
51
64
|
|
65
|
+
# Adds the given number of banking days, i.e. bank holidays don't count.
|
66
|
+
# If days is negative, subtracts the given number of banking days.
|
67
|
+
# If days is zero, returns self.
|
52
68
|
def add_banking_days(days)
|
53
69
|
day = self
|
54
70
|
if days > 0
|
@@ -58,6 +74,12 @@ module UsBankHolidays
|
|
58
74
|
end
|
59
75
|
day
|
60
76
|
end
|
77
|
+
|
78
|
+
# Returns true if this is a banking day, i.e. is not a bank holiday,
|
79
|
+
# false otherwise.
|
80
|
+
def banking_day?
|
81
|
+
!bank_holiday?
|
82
|
+
end
|
61
83
|
end
|
62
84
|
|
63
85
|
end
|
@@ -88,21 +88,33 @@ 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
|
+
UsBankHolidays.bank_holiday?(holiday).should be_true
|
93
|
+
UsBankHolidays.banking_day?(holiday).should be_false
|
94
|
+
}
|
92
95
|
end
|
93
96
|
|
94
97
|
it 'weekends should be bank holidays' do
|
95
|
-
sample_weekends.each{ |weekend|
|
98
|
+
sample_weekends.each{ |weekend|
|
99
|
+
UsBankHolidays.bank_holiday?(weekend).should be_true
|
100
|
+
UsBankHolidays.banking_day?(weekend).should be_false
|
101
|
+
}
|
96
102
|
end
|
97
103
|
|
98
104
|
it 'regular days should not be bank holidays' do
|
99
|
-
sample_weekdays.each { |day|
|
105
|
+
sample_weekdays.each { |day|
|
106
|
+
UsBankHolidays.bank_holiday?(day).should be_false
|
107
|
+
UsBankHolidays.banking_day?(day).should be_true
|
108
|
+
}
|
100
109
|
end
|
101
110
|
end
|
102
111
|
|
103
112
|
describe '.weekend?' do
|
104
113
|
it 'should recognize weekends' do
|
105
|
-
sample_weekends.each{ |weekend|
|
114
|
+
sample_weekends.each{ |weekend|
|
115
|
+
UsBankHolidays.weekend?(weekend).should be_true
|
116
|
+
UsBankHolidays.banking_day?(weekend).should be_false
|
117
|
+
}
|
106
118
|
end
|
107
119
|
|
108
120
|
it 'weekdays should not be considered weekends' do
|
@@ -115,7 +127,10 @@ describe UsBankHolidays do
|
|
115
127
|
describe '.bank_holiday?' do
|
116
128
|
|
117
129
|
it 'should recognize bank holidays' do
|
118
|
-
sample_holidays.each{ |holiday|
|
130
|
+
sample_holidays.each{ |holiday|
|
131
|
+
holiday.bank_holiday?.should be_true
|
132
|
+
holiday.banking_day?.should be_false
|
133
|
+
}
|
119
134
|
end
|
120
135
|
|
121
136
|
it 'should treat weekends as bank holidays' do
|
@@ -123,7 +138,10 @@ describe UsBankHolidays do
|
|
123
138
|
end
|
124
139
|
|
125
140
|
it 'should not treat regular weekdays as bank holidays' do
|
126
|
-
sample_weekdays.each { |day|
|
141
|
+
sample_weekdays.each { |day|
|
142
|
+
day.bank_holiday?.should be_false
|
143
|
+
day.banking_day?.should be_true
|
144
|
+
}
|
127
145
|
end
|
128
146
|
|
129
147
|
it 'if Jan. 1 falls on a Saturday, Dec. 31 of the previous year should be a bank holiday' do
|
@@ -134,11 +152,17 @@ describe UsBankHolidays do
|
|
134
152
|
describe '.weekend?' do
|
135
153
|
|
136
154
|
it 'should recognize weekends' do
|
137
|
-
sample_weekends.each{ |weekend|
|
155
|
+
sample_weekends.each{ |weekend|
|
156
|
+
weekend.weekend?.should be_true
|
157
|
+
weekend.banking_day?.should be_false
|
158
|
+
}
|
138
159
|
end
|
139
160
|
|
140
161
|
it 'weekdays should not be considered weekends' do
|
141
|
-
sample_weekdays.each { |day|
|
162
|
+
sample_weekdays.each { |day|
|
163
|
+
day.weekend?.should be_false
|
164
|
+
day.banking_day?.should be_true
|
165
|
+
}
|
142
166
|
end
|
143
167
|
|
144
168
|
end
|
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.2
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- .travis.yml
|
76
77
|
- Gemfile
|
77
78
|
- LICENSE.txt
|
78
79
|
- README.md
|