us_bank_holidays 0.0.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -3
- data/README.md +13 -2
- data/lib/us_bank_holidays.rb +31 -4
- data/lib/us_bank_holidays/holiday_year.rb +30 -23
- data/lib/us_bank_holidays/version.rb +1 -1
- data/spec/functional/holiday_year_spec.rb +101 -16
- data/spec/functional/month_spec.rb +5 -5
- data/spec/functional/us_bank_holidays_spec.rb +73 -36
- data/spec/spec_helper.rb +3 -1
- data/us_bank_holidays.gemspec +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f9ef1ece79b15a1e2431e7627d0bc36914e86fb0e76b39310551d4198c728d0
|
4
|
+
data.tar.gz: c27c824131609ffcb000915313d80778322f88ffbaef9ab52c8a8c0137db55fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd9bc1def99590c5e5b706f2e0ccdc60c3e346b7c8f6e0d8900dd34462ff1e28dc1a362f13f33e8a911d8d8111a8f02b44fcbb7b14ff254a764b5349174571fc
|
7
|
+
data.tar.gz: d8324975d14a8ca035620bb572dfce8ac159ab18edc5d3540a91553ad48815acbd561313768405da41abd03379df06c32a8f585dcb942e35adb21483de13cee5
|
data/.travis.yml
CHANGED
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
|
|
@@ -11,8 +12,8 @@ Patches `Date` to make working with US bank holidays easier
|
|
11
12
|
|
12
13
|
Tested against the following Ruby runtimes:
|
13
14
|
|
14
|
-
* MRI
|
15
|
-
* JRuby
|
15
|
+
* MRI 2.3, 2.4, 2.5
|
16
|
+
* JRuby 9
|
16
17
|
* Rubinius (latest)
|
17
18
|
|
18
19
|
## Installation
|
@@ -45,11 +46,21 @@ date.bank_holiday? # Returns false
|
|
45
46
|
date.weekend? # Returns false
|
46
47
|
date.next_banking_day # Returns Monday, January 6, 2014
|
47
48
|
date.banking_day? # Returns true
|
49
|
+
date.first_banking_day_of_month? # Returns false
|
50
|
+
date.last_banking_day_of_month? # Returns false
|
48
51
|
|
49
52
|
Date.new(2014, 1, 16).add_banking_days(2) # Returns Tuesday, January 21, 2014
|
50
53
|
Date.new(2014, 1, 5).previous_banking_day # Returns Friday, January 3, 2014
|
51
54
|
```
|
52
55
|
|
56
|
+
By default, weekends always count as bank holidays, but this can be disabled.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
date = Date.new(2014, 2, 2) # Sunday, February 2, 2014
|
60
|
+
date.bank_holiday? # Returns true
|
61
|
+
date.bank_holiday?(false) # Returns false
|
62
|
+
```
|
63
|
+
|
53
64
|
## Contributing
|
54
65
|
|
55
66
|
1. Fork it
|
data/lib/us_bank_holidays.rb
CHANGED
@@ -12,9 +12,16 @@ 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
|
+
# 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)
|
19
|
+
def self.bank_holiday?(date, include_weekends = true)
|
20
|
+
if include_weekends && weekend?(date)
|
21
|
+
true
|
22
|
+
else
|
17
23
|
::UsBankHolidays::HolidayYear.new(date.year).bank_holidays.include?(date)
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
27
|
# Returns true if the given date is a banking day, i.e. is not a bank holiday,
|
@@ -39,6 +46,12 @@ module UsBankHolidays
|
|
39
46
|
end
|
40
47
|
end
|
41
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
|
+
|
42
55
|
# Instance methods to be injected into the Date class
|
43
56
|
module DateMethods
|
44
57
|
|
@@ -48,8 +61,12 @@ module UsBankHolidays
|
|
48
61
|
end
|
49
62
|
|
50
63
|
# Returns true if the date is a bank holiday, false otherwise.
|
51
|
-
|
52
|
-
|
64
|
+
# Pass the optional 'include_weekends' to control whether weekends should count as
|
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)
|
68
|
+
def bank_holiday?(include_weekends = true)
|
69
|
+
::UsBankHolidays.bank_holiday? self, include_weekends
|
53
70
|
end
|
54
71
|
|
55
72
|
# Returns the next banking day after this one.
|
@@ -80,6 +97,16 @@ module UsBankHolidays
|
|
80
97
|
def banking_day?
|
81
98
|
!bank_holiday?
|
82
99
|
end
|
100
|
+
|
101
|
+
# Returns true if the date is the last banking day of the month, false otherwise.
|
102
|
+
def last_banking_day_of_month?
|
103
|
+
!bank_holiday? && next_banking_day.month != month
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns true if the date is the first banking day of the month, false otherwise.
|
107
|
+
def first_banking_day_of_month?
|
108
|
+
!bank_holiday? && previous_banking_day.month != month
|
109
|
+
end
|
83
110
|
end
|
84
111
|
|
85
112
|
end
|
@@ -9,6 +9,7 @@ module UsBankHolidays
|
|
9
9
|
:mlk_day,
|
10
10
|
:washingtons_birthday,
|
11
11
|
:memorial_day,
|
12
|
+
:juneteenth,
|
12
13
|
:independence_day,
|
13
14
|
:labor_day,
|
14
15
|
:columbus_day,
|
@@ -16,8 +17,9 @@ module UsBankHolidays
|
|
16
17
|
:thanksgiving,
|
17
18
|
:christmas
|
18
19
|
|
20
|
+
# Initializes instance from a given year
|
19
21
|
def initialize(year)
|
20
|
-
@year
|
22
|
+
@year = year
|
21
23
|
|
22
24
|
init_fixed_holidays
|
23
25
|
init_rolled_holidays
|
@@ -25,26 +27,27 @@ module UsBankHolidays
|
|
25
27
|
end
|
26
28
|
|
27
29
|
# Returns the federal holidays for the given year on the dates they will actually
|
28
|
-
# be observed.
|
29
|
-
# Saturday December 31 will also be included.
|
30
|
+
# be observed.
|
30
31
|
def bank_holidays
|
31
32
|
@bank_holidays ||= begin
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
33
|
+
holidays = [
|
34
|
+
new_years_day,
|
35
|
+
mlk_day,
|
36
|
+
washingtons_birthday,
|
37
|
+
memorial_day,
|
38
|
+
juneteenth,
|
39
|
+
independence_day,
|
40
|
+
labor_day,
|
41
|
+
columbus_day,
|
42
|
+
veterans_day,
|
43
|
+
thanksgiving,
|
44
|
+
christmas
|
45
|
+
].compact
|
46
|
+
if Date.new(year + 1, 1, 1).saturday?
|
47
|
+
holidays << Date.new(year, 12, 31)
|
48
|
+
end
|
49
|
+
holidays.freeze
|
50
|
+
end
|
48
51
|
end
|
49
52
|
|
50
53
|
{
|
@@ -96,7 +99,10 @@ module UsBankHolidays
|
|
96
99
|
# First of the year, rolls either forward or back.
|
97
100
|
@new_years_day = roll_nominal(Date.new(year, 1, 1))
|
98
101
|
|
99
|
-
#
|
102
|
+
# 19th of June
|
103
|
+
@juneteenth = (year > 2020 ? roll_nominal(Date.new(year, 6, 19)) : nil )
|
104
|
+
|
105
|
+
# 4th of July
|
100
106
|
@independence_day = roll_nominal(Date.new(year, 7, 4))
|
101
107
|
|
102
108
|
# November 11
|
@@ -106,11 +112,12 @@ module UsBankHolidays
|
|
106
112
|
@christmas = roll_nominal(Date.new(year, 12, 25))
|
107
113
|
end
|
108
114
|
|
109
|
-
# Figures out where to roll the given nominal date. If it's a Saturday
|
110
|
-
#
|
115
|
+
# Figures out where to roll the given nominal date. If it's a Saturday and
|
116
|
+
# Saturday holiday date rolling is enabled (see UsBankHolidays#saturday_holiday_date_rolling?),
|
117
|
+
# assumes it's the day before (Friday), if Sunday it's the date after (Monday), otherwise
|
111
118
|
# just returns self.
|
112
119
|
def roll_nominal(nominal)
|
113
|
-
if nominal.saturday?
|
120
|
+
if nominal.saturday? && ::UsBankHolidays.saturday_holiday_date_rolling?
|
114
121
|
nominal - 1
|
115
122
|
elsif nominal.sunday?
|
116
123
|
nominal + 1
|
@@ -1,20 +1,105 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe UsBankHolidays::HolidayYear do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
3
|
+
RSpec.describe UsBankHolidays::HolidayYear do
|
4
|
+
|
5
|
+
context "should determine bank holidays" do
|
6
|
+
|
7
|
+
context "Before 2021" do
|
8
|
+
|
9
|
+
context "Force Saturday date rolling" do
|
10
|
+
before :each do
|
11
|
+
allow(::UsBankHolidays).to receive(:saturday_holiday_date_rolling?).and_return(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should determine bank holidays' do
|
15
|
+
expect(UsBankHolidays::HolidayYear.new(2017).bank_holidays).to eq([
|
16
|
+
'2017-01-02', #New Year’s Day
|
17
|
+
'2017-01-16', #Birthday of Martin Luther King, Jr.
|
18
|
+
'2017-02-20', #Washington’s Birthday
|
19
|
+
'2017-05-29', #Memorial Day
|
20
|
+
'2017-07-04', #Independence Day
|
21
|
+
'2017-09-04', #Labor Day
|
22
|
+
'2017-10-09', #Columbus Day
|
23
|
+
'2017-11-10', #Veterans Day
|
24
|
+
'2017-11-23', #Thanksgiving Day
|
25
|
+
'2017-12-25' #Christmas Day
|
26
|
+
].map { |d| Date.parse(d) }
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context "No Saturday date rolling" do
|
33
|
+
it 'should determine bank holidays' do
|
34
|
+
expect(UsBankHolidays::HolidayYear.new(2017).bank_holidays).to eq([
|
35
|
+
'2017-01-02', #New Year’s Day
|
36
|
+
'2017-01-16', #Birthday of Martin Luther King, Jr.
|
37
|
+
'2017-02-20', #Washington’s Birthday
|
38
|
+
'2017-05-29', #Memorial Day
|
39
|
+
'2017-07-04', #Independence Day
|
40
|
+
'2017-09-04', #Labor Day
|
41
|
+
'2017-10-09', #Columbus Day
|
42
|
+
'2017-11-11', #Veterans Day
|
43
|
+
'2017-11-23', #Thanksgiving Day
|
44
|
+
'2017-12-25' #Christmas Day
|
45
|
+
].map { |d| Date.parse(d) }
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
context "2021 and later" do
|
54
|
+
|
55
|
+
context "Force Saturday date rolling" do
|
56
|
+
before :each do
|
57
|
+
allow(::UsBankHolidays).to receive(:saturday_holiday_date_rolling?).and_return(true)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should determine bank holidays' do
|
61
|
+
expect(UsBankHolidays::HolidayYear.new(2021).bank_holidays).to eq([
|
62
|
+
'2021-01-01', #New Year’s Day
|
63
|
+
'2021-01-18', #Birthday of Martin Luther King, Jr.
|
64
|
+
'2021-02-15', #Washington’s Birthday
|
65
|
+
'2021-05-31', #Memorial Day
|
66
|
+
'2021-06-18', #Juneteenth
|
67
|
+
'2021-07-05', #Independence Day
|
68
|
+
'2021-09-06', #Labor Day
|
69
|
+
'2021-10-11', #Columbus Day
|
70
|
+
'2021-11-11', #Veterans Day
|
71
|
+
'2021-11-25', #Thanksgiving Day
|
72
|
+
'2021-12-24', #Christmas Day
|
73
|
+
'2021-12-31' #New Year’s Day
|
74
|
+
].map { |d| Date.parse(d) }
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
context "No Saturday date rolling" do
|
81
|
+
it 'should determine bank holidays' do
|
82
|
+
expect(UsBankHolidays::HolidayYear.new(2021).bank_holidays).to eq([
|
83
|
+
'2021-01-01', #New Year’s Day
|
84
|
+
'2021-01-18', #Birthday of Martin Luther King, Jr.
|
85
|
+
'2021-02-15', #Washington’s Birthday
|
86
|
+
'2021-05-31', #Memorial Day
|
87
|
+
'2021-06-19', #Juneteenth
|
88
|
+
'2021-07-05', #Independence Day
|
89
|
+
'2021-09-06', #Labor Day
|
90
|
+
'2021-10-11', #Columbus Day
|
91
|
+
'2021-11-11', #Veterans Day
|
92
|
+
'2021-11-25', #Thanksgiving Day
|
93
|
+
'2021-12-25', #Christmas Day
|
94
|
+
'2021-12-31' #New Year’s Day
|
95
|
+
].map { |d| Date.parse(d) }
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
18
103
|
end
|
19
104
|
|
20
105
|
it 'should declare Dec. 31 a bank holiday if it falls on a Friday' do
|
@@ -39,7 +124,7 @@ describe UsBankHolidays::HolidayYear do
|
|
39
124
|
:december => 12
|
40
125
|
}.each do |month_name, month_index|
|
41
126
|
it "should respond to '#{month_name}' and return the right month" do
|
42
|
-
year.respond_to?(month_name).
|
127
|
+
expect(year.respond_to?(month_name)).to eq(true)
|
43
128
|
month = year.send(month_name)
|
44
129
|
month.year.should == 2014
|
45
130
|
month.month.should == month_index
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe UsBankHolidays::Month do
|
3
|
+
RSpec.describe UsBankHolidays::Month do
|
4
4
|
let(:january) { UsBankHolidays::Month.new(2014, 1) }
|
5
5
|
|
6
6
|
it 'should record the correct month' do
|
@@ -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
|
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
|
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
|
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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe UsBankHolidays do
|
3
|
+
RSpec.describe UsBankHolidays do
|
4
4
|
let(:sample_holidays) {
|
5
5
|
[
|
6
6
|
'2014-01-01', #New Year’s Day
|
@@ -86,85 +86,102 @@ 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
|
-
sample_holidays.each{ |holiday|
|
92
|
-
UsBankHolidays.bank_holiday?(holiday).should
|
93
|
-
UsBankHolidays.banking_day?(holiday).should
|
95
|
+
sample_holidays.each { |holiday|
|
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
|
-
sample_weekends.each{ |weekend|
|
99
|
-
UsBankHolidays.bank_holiday?(weekend).should
|
100
|
-
UsBankHolidays.banking_day?(weekend).should
|
102
|
+
sample_weekends.each { |weekend|
|
103
|
+
UsBankHolidays.bank_holiday?(weekend).should eq(true)
|
104
|
+
UsBankHolidays.banking_day?(weekend).should eq(false)
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should exclude weekends if the appropriate flag is passed' do
|
109
|
+
sample_weekends.each { |weekend|
|
110
|
+
UsBankHolidays.bank_holiday?(weekend, false).should eq(false)
|
101
111
|
}
|
102
112
|
end
|
103
113
|
|
104
114
|
it 'regular days should not be bank holidays' do
|
105
115
|
sample_weekdays.each { |day|
|
106
|
-
UsBankHolidays.bank_holiday?(day).should
|
107
|
-
UsBankHolidays.banking_day?(day).should
|
116
|
+
UsBankHolidays.bank_holiday?(day).should eq(false)
|
117
|
+
UsBankHolidays.banking_day?(day).should eq(true)
|
108
118
|
}
|
109
119
|
end
|
110
120
|
end
|
111
121
|
|
112
122
|
describe '.weekend?' do
|
113
123
|
it 'should recognize weekends' do
|
114
|
-
sample_weekends.each{ |weekend|
|
115
|
-
UsBankHolidays.weekend?(weekend).should
|
116
|
-
UsBankHolidays.banking_day?(weekend).should
|
124
|
+
sample_weekends.each { |weekend|
|
125
|
+
UsBankHolidays.weekend?(weekend).should eq(true)
|
126
|
+
UsBankHolidays.banking_day?(weekend).should eq(false)
|
117
127
|
}
|
118
128
|
end
|
119
129
|
|
120
130
|
it 'weekdays should not be considered weekends' do
|
121
|
-
sample_weekdays.each { |day| UsBankHolidays.weekend?(day).should
|
131
|
+
sample_weekdays.each { |day| UsBankHolidays.weekend?(day).should eq(false) }
|
122
132
|
end
|
123
133
|
end
|
124
134
|
|
125
135
|
describe ::UsBankHolidays::DateMethods do
|
126
136
|
|
127
|
-
describe '.
|
137
|
+
describe '.weekend?' do
|
128
138
|
|
129
|
-
it 'should recognize
|
130
|
-
|
131
|
-
|
132
|
-
|
139
|
+
it 'should recognize weekends' do
|
140
|
+
sample_weekends.each { |weekend|
|
141
|
+
weekend.weekend?.should eq(true)
|
142
|
+
weekend.banking_day?.should eq(false)
|
133
143
|
}
|
134
144
|
end
|
135
145
|
|
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
|
146
|
+
it 'weekdays should not be considered weekends' do
|
141
147
|
sample_weekdays.each { |day|
|
142
|
-
day.
|
143
|
-
day.banking_day?.should
|
148
|
+
day.weekend?.should eq(false)
|
149
|
+
day.banking_day?.should eq(true)
|
144
150
|
}
|
145
151
|
end
|
146
152
|
|
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
153
|
end
|
151
154
|
|
152
|
-
describe '.
|
155
|
+
describe '.bank_holiday?' do
|
153
156
|
|
154
|
-
it 'should recognize
|
155
|
-
|
156
|
-
|
157
|
-
|
157
|
+
it 'should recognize bank holidays' do
|
158
|
+
sample_holidays.each { |holiday|
|
159
|
+
holiday.bank_holiday?.should eq(true)
|
160
|
+
holiday.banking_day?.should eq(false)
|
158
161
|
}
|
159
162
|
end
|
160
163
|
|
161
|
-
it '
|
164
|
+
it 'should treat weekends as bank holidays' do
|
165
|
+
sample_weekends.each { |weekend| weekend.bank_holiday?.should eq(true) }
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should exclude weekends if the appropriate flag is passed' do
|
169
|
+
sample_weekends.each { |weekend|
|
170
|
+
weekend.weekend?.should eq(true)
|
171
|
+
weekend.bank_holiday?(false).should eq(false)
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should not treat regular weekdays as bank holidays' do
|
162
176
|
sample_weekdays.each { |day|
|
163
|
-
day.
|
164
|
-
day.banking_day?.should
|
177
|
+
day.bank_holiday?.should eq(false)
|
178
|
+
day.banking_day?.should eq(true)
|
165
179
|
}
|
166
180
|
end
|
167
181
|
|
182
|
+
it 'if Jan. 1 falls on a Saturday, Dec. 31 of the previous year should be a bank holiday' do
|
183
|
+
Date.new(2021, 12, 31).bank_holiday?.should eq(true)
|
184
|
+
end
|
168
185
|
end
|
169
186
|
|
170
187
|
describe '.next_banking_day' do
|
@@ -204,5 +221,25 @@ describe UsBankHolidays do
|
|
204
221
|
Date.new(2014, 1, 21).add_banking_days(-2).should == Date.new(2014, 1, 16)
|
205
222
|
end
|
206
223
|
end
|
224
|
+
|
225
|
+
describe '.last_banking_day_of_month?' do
|
226
|
+
it 'should determine if a date is the last banking day of the month' do
|
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)
|
229
|
+
|
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)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe '.first_banking_day_of_month?' do
|
236
|
+
it 'should determine if the date if the first banking day of the month' do
|
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)
|
239
|
+
|
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)
|
242
|
+
end
|
243
|
+
end
|
207
244
|
end
|
208
245
|
end
|
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`.
|
data/us_bank_holidays.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
23
|
spec.add_development_dependency 'rspec'
|
24
24
|
spec.add_development_dependency 'simplecov'
|
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
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2021-08-10 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
|
-
version: '
|
19
|
+
version: '0'
|
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
|
-
version: '
|
26
|
+
version: '0'
|
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.
|
110
|
+
rubygems_version: 2.7.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.
|