us_bank_holidays 0.0.5 → 0.2.1

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
- SHA1:
3
- metadata.gz: b60841173b3f8f7871352347c1182b85a23dc144
4
- data.tar.gz: 0aaa072931196f5f0f6a342efb0f4ae831280097
2
+ SHA256:
3
+ metadata.gz: 8db39160147df2816e65af1fd851ff2fdc9488bdc189101c7bc03e86395a0189
4
+ data.tar.gz: ad4e2585e1539f8d82e8f1b11dd1b10b9625c57f019e85944a1b961baf699af9
5
5
  SHA512:
6
- metadata.gz: 4a523666e1a6f5b81383b8592c13de633e55a8101bbfc8e2fae9daa2acd651e172d2b45f6fa9897169394b6faed24de7ad3be0cea54118bbada2be319176a08f
7
- data.tar.gz: c075e3c186c6420301a838125a6ba02cd993ac412ba269155ea42341450d6f00ca9f7d2d2fe68b5b8b6f457290f8c5ce5f097c9bbdb1c60fb0bf80961bf77e36
6
+ metadata.gz: 5f4933efb849b3df1673ccf858494d9ba183baa980193a980a15ccb0adf51d3527b42ce4a8c93a23bb402b0399f0510d14aaebf6c38f0a8b875a6172b7f43703
7
+ data.tar.gz: b78c5d1a86ae39a7307155580d8c33b15d0feb317fee9a680a1fbb7bcb20ee60a14b2e7444d11020937b2a5222bd1f31ec3cd2cdbf6c4028d18badd6ace3973f
data/.travis.yml CHANGED
@@ -1,9 +1,9 @@
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.3
5
+ - 2.4
6
+ - 2.5
7
7
  - jruby
8
8
  - rbx
9
9
  matrix:
data/README.md CHANGED
@@ -12,8 +12,8 @@ Patches `Date` to make working with US bank holidays easier
12
12
 
13
13
  Tested against the following Ruby runtimes:
14
14
 
15
- * MRI 1.9.3, 2.0.0, 2.1.0
16
- * JRuby 1.7+
15
+ * MRI 2.3, 2.4, 2.5
16
+ * JRuby 9
17
17
  * Rubinius (latest)
18
18
 
19
19
  ## Installation
@@ -46,6 +46,8 @@ date.bank_holiday? # Returns false
46
46
  date.weekend? # Returns false
47
47
  date.next_banking_day # Returns Monday, January 6, 2014
48
48
  date.banking_day? # Returns true
49
+ date.first_banking_day_of_month? # Returns false
50
+ date.last_banking_day_of_month? # Returns false
49
51
 
50
52
  Date.new(2014, 1, 16).add_banking_days(2) # Returns Tuesday, January 21, 2014
51
53
  Date.new(2014, 1, 5).previous_banking_day # Returns Friday, January 3, 2014
@@ -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,
@@ -26,26 +27,27 @@ module UsBankHolidays
26
27
  end
27
28
 
28
29
  # 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.
30
+ # be observed.
31
31
  def bank_holidays
32
32
  @bank_holidays ||= begin
33
- holidays = [ new_years_day,
34
- mlk_day,
35
- washingtons_birthday,
36
- memorial_day,
37
- independence_day,
38
- labor_day,
39
- columbus_day,
40
- veterans_day,
41
- thanksgiving,
42
- christmas
43
- ]
44
- if Date.new(year + 1, 1, 1).saturday?
45
- holidays << Date.new(year, 12, 31)
46
- end
47
- holidays.freeze
48
- end
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? && ::UsBankHolidays.saturday_holiday_date_rolling?
47
+ holidays << Date.new(year, 12, 31)
48
+ end
49
+ holidays.freeze
50
+ end
49
51
  end
50
52
 
51
53
  {
@@ -97,7 +99,10 @@ module UsBankHolidays
97
99
  # First of the year, rolls either forward or back.
98
100
  @new_years_day = roll_nominal(Date.new(year, 1, 1))
99
101
 
100
- # 4'th of July
102
+ # 19th of June
103
+ @juneteenth = (year > 2020 ? roll_nominal(Date.new(year, 6, 19)) : nil )
104
+
105
+ # 4th of July
101
106
  @independence_day = roll_nominal(Date.new(year, 7, 4))
102
107
 
103
108
  # November 11
@@ -107,11 +112,12 @@ module UsBankHolidays
107
112
  @christmas = roll_nominal(Date.new(year, 12, 25))
108
113
  end
109
114
 
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
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
112
118
  # just returns self.
113
119
  def roll_nominal(nominal)
114
- if nominal.saturday?
120
+ if nominal.saturday? && ::UsBankHolidays.saturday_holiday_date_rolling?
115
121
  nominal - 1
116
122
  elsif nominal.sunday?
117
123
  nominal + 1
@@ -1,3 +1,3 @@
1
1
  module UsBankHolidays
2
- VERSION = "0.0.5"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -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
@@ -87,6 +97,16 @@ module UsBankHolidays
87
97
  def banking_day?
88
98
  !bank_holiday?
89
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
90
110
  end
91
111
 
92
112
  end
@@ -1,24 +1,109 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe UsBankHolidays::HolidayYear do
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) }
18
- end
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
+
57
+ before :each do
58
+ allow(::UsBankHolidays).to receive(:saturday_holiday_date_rolling?).and_return(true)
59
+ end
60
+
61
+ it 'should determine bank holidays' do
62
+ expect(UsBankHolidays::HolidayYear.new(2021).bank_holidays).to eq([
63
+ '2021-01-01', #New Year’s Day
64
+ '2021-01-18', #Birthday of Martin Luther King, Jr.
65
+ '2021-02-15', #Washington’s Birthday
66
+ '2021-05-31', #Memorial Day
67
+ '2021-06-18', #Juneteenth
68
+ '2021-07-05', #Independence Day
69
+ '2021-09-06', #Labor Day
70
+ '2021-10-11', #Columbus Day
71
+ '2021-11-11', #Veterans Day
72
+ '2021-11-25', #Thanksgiving Day
73
+ '2021-12-24', #Christmas Day
74
+ '2021-12-31' #New Year’s Day
75
+ ].map { |d| Date.parse(d) }
76
+ )
77
+ end
78
+
79
+ end
80
+
81
+ context "No Saturday date rolling" do
82
+ before :each do
83
+ allow(::UsBankHolidays).to receive(:saturday_holiday_date_rolling?).and_return(false)
84
+ end
85
+
86
+ it 'should determine bank holidays' do
87
+ expect(UsBankHolidays::HolidayYear.new(2021).bank_holidays).to eq([
88
+ '2021-01-01', #New Year’s Day
89
+ '2021-01-18', #Birthday of Martin Luther King, Jr.
90
+ '2021-02-15', #Washington’s Birthday
91
+ '2021-05-31', #Memorial Day
92
+ '2021-06-19', #Juneteenth
93
+ '2021-07-05', #Independence Day
94
+ '2021-09-06', #Labor Day
95
+ '2021-10-11', #Columbus Day
96
+ '2021-11-11', #Veterans Day
97
+ '2021-11-25', #Thanksgiving Day
98
+ '2021-12-25' #Christmas Day
99
+ ].map { |d| Date.parse(d) }
100
+ )
101
+ end
102
+
103
+ end
104
+
105
+ end
19
106
 
20
- it 'should declare Dec. 31 a bank holiday if it falls on a Friday' do
21
- UsBankHolidays::HolidayYear.new(2021).bank_holidays.last.should == Date.new(2021, 12, 31)
22
107
  end
23
108
 
24
109
  context 'Months' 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).should be_true
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 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
@@ -1,221 +1,282 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe UsBankHolidays do
4
- let(:sample_holidays) {
5
- [
6
- '2014-01-01', #New Year’s Day
7
- '2014-01-20', #Birthday of Martin Luther King, Jr.
8
- '2014-02-17', #Washington’s Birthday
9
- '2014-05-26', #Memorial Day
10
- '2014-07-04', #Independence Day
11
- '2014-09-01', #Labor Day
12
- '2014-10-13', #Columbus Day
13
- '2014-11-11', #Veterans Day
14
- '2014-11-27', #Thanksgiving Day
15
- '2014-12-25', #Christmas Day
16
-
17
- '2015-01-01', #New Year’s Day
18
- '2015-01-19', #Birthday of Martin Luther King, Jr.
19
- '2015-02-16', #Washington’s Birthday
20
- '2015-05-25', #Memorial Day
21
- '2015-07-03', #Independence Day
22
- '2015-09-07', #Labor Day
23
- '2015-10-12', #Columbus Day
24
- '2015-11-11', #Veterans Day
25
- '2015-11-26', #Thanksgiving Day
26
- '2015-12-25', #Christmas Day
27
-
28
- '2016-01-01', #New Year’s Day
29
- '2016-01-18', #Birthday of Martin Luther King, Jr.
30
- '2016-02-15', #Washington’s Birthday
31
- '2016-05-30', #Memorial Day
32
- '2016-07-04', #Independence Day
33
- '2016-09-05', #Labor Day
34
- '2016-10-10', #Columbus Day
35
- '2016-11-11', #Veterans Day
36
- '2016-11-24', #Thanksgiving Day
37
- '2016-12-26', #Christmas Day
38
-
39
- '2017-01-02', #New Year’s Day
40
- '2017-01-16', #Birthday of Martin Luther King, Jr.
41
- '2017-02-20', #Washington’s Birthday
42
- '2017-05-29', #Memorial Day
43
- '2017-07-04', #Independence Day
44
- '2017-09-04', #Labor Day
45
- '2017-10-09', #Columbus Day
46
- '2017-11-10', #Veterans Day
47
- '2017-11-23', #Thanksgiving Day
48
- '2017-12-25', #Christmas Day
49
-
50
- '2018-01-01', #New Year’s Day
51
- '2018-01-15', #Birthday of Martin Luther King, Jr.
52
- '2018-02-19', #Washington’s Birthday
53
- '2018-05-28', #Memorial Day
54
- '2018-07-04', #Independence Day
55
- '2018-09-03', #Labor Day
56
- '2018-10-08', #Columbus Day
57
- '2018-11-12', #Veterans Day
58
- '2018-11-22', #Thanksgiving Day
59
- '2018-12-25', #Christmas Day
60
-
61
- '2019-01-01', #New Year’s Day
62
- '2019-01-21', #Birthday of Martin Luther King, Jr.
63
- '2019-02-18', #Washington’s Birthday
64
- '2019-05-27', #Memorial Day
65
- '2019-07-04', #Independence Day
66
- '2019-09-02', #Labor Day
67
- '2019-10-14', #Columbus Day
68
- '2019-11-11', #Veterans Day
69
- '2019-11-28', #Thanksgiving Day
70
- '2019-12-25', #Christmas Day
71
-
72
- '2020-01-01', #New Year’s Day
73
- '2020-01-20', #Birthday of Martin Luther King, Jr.
74
- '2020-02-17', #Washington’s Birthday
75
- '2020-05-25', #Memorial Day
76
- '2020-07-03', #Independence Day
77
- '2020-09-07', #Labor Day
78
- '2020-10-12', #Columbus Day
79
- '2020-11-11', #Veterans Day
80
- '2020-11-26', #Thanksgiving Day
81
- '2020-12-25' #Christmas Day
82
- ].map {|date_str| Date.parse(date_str) }
83
- }
3
+ RSpec.describe UsBankHolidays do
84
4
 
85
5
  let(:sample_weekends) { [Date.new(2014, 2, 1), Date.new(2014, 2, 2)] }
86
6
 
87
7
  let(:sample_weekdays) { [3, 4, 5, 6, 7].map{|d| Date.new(2014, 2, d) } }
88
8
 
89
- describe '.bank_holiday?' do
90
- it 'should determine bank holidays on the list' do
91
- sample_holidays.each { |holiday|
92
- UsBankHolidays.bank_holiday?(holiday).should be_true
93
- UsBankHolidays.banking_day?(holiday).should be_false
94
- }
95
- end
96
-
97
- it 'weekends should be bank holidays' do
98
- sample_weekends.each { |weekend|
99
- UsBankHolidays.bank_holiday?(weekend).should be_true
100
- UsBankHolidays.banking_day?(weekend).should be_false
101
- }
9
+ context "with saturday holiday date rolling" do
10
+
11
+ let(:sample_holidays) {
12
+ [
13
+ '2014-01-01', #New Year’s Day
14
+ '2014-01-20', #Birthday of Martin Luther King, Jr.
15
+ '2014-02-17', #Washington’s Birthday
16
+ '2014-05-26', #Memorial Day
17
+ '2014-07-04', #Independence Day
18
+ '2014-09-01', #Labor Day
19
+ '2014-10-13', #Columbus Day
20
+ '2014-11-11', #Veterans Day
21
+ '2014-11-27', #Thanksgiving Day
22
+ '2014-12-25', #Christmas Day
23
+
24
+ '2015-01-01', #New Year’s Day
25
+ '2015-01-19', #Birthday of Martin Luther King, Jr.
26
+ '2015-02-16', #Washington’s Birthday
27
+ '2015-05-25', #Memorial Day
28
+ '2015-07-03', #Independence Day
29
+ '2015-09-07', #Labor Day
30
+ '2015-10-12', #Columbus Day
31
+ '2015-11-11', #Veterans Day
32
+ '2015-11-26', #Thanksgiving Day
33
+ '2015-12-25', #Christmas Day
34
+
35
+ '2016-01-01', #New Year’s Day
36
+ '2016-01-18', #Birthday of Martin Luther King, Jr.
37
+ '2016-02-15', #Washington’s Birthday
38
+ '2016-05-30', #Memorial Day
39
+ '2016-07-04', #Independence Day
40
+ '2016-09-05', #Labor Day
41
+ '2016-10-10', #Columbus Day
42
+ '2016-11-11', #Veterans Day
43
+ '2016-11-24', #Thanksgiving Day
44
+ '2016-12-26', #Christmas Day
45
+
46
+ '2017-01-02', #New Year’s Day
47
+ '2017-01-16', #Birthday of Martin Luther King, Jr.
48
+ '2017-02-20', #Washington’s Birthday
49
+ '2017-05-29', #Memorial Day
50
+ '2017-07-04', #Independence Day
51
+ '2017-09-04', #Labor Day
52
+ '2017-10-09', #Columbus Day
53
+ '2017-11-10', #Veterans Day
54
+ '2017-11-23', #Thanksgiving Day
55
+ '2017-12-25', #Christmas Day
56
+
57
+ '2018-01-01', #New Year’s Day
58
+ '2018-01-15', #Birthday of Martin Luther King, Jr.
59
+ '2018-02-19', #Washington’s Birthday
60
+ '2018-05-28', #Memorial Day
61
+ '2018-07-04', #Independence Day
62
+ '2018-09-03', #Labor Day
63
+ '2018-10-08', #Columbus Day
64
+ '2018-11-12', #Veterans Day
65
+ '2018-11-22', #Thanksgiving Day
66
+ '2018-12-25', #Christmas Day
67
+
68
+ '2019-01-01', #New Year’s Day
69
+ '2019-01-21', #Birthday of Martin Luther King, Jr.
70
+ '2019-02-18', #Washington’s Birthday
71
+ '2019-05-27', #Memorial Day
72
+ '2019-07-04', #Independence Day
73
+ '2019-09-02', #Labor Day
74
+ '2019-10-14', #Columbus Day
75
+ '2019-11-11', #Veterans Day
76
+ '2019-11-28', #Thanksgiving Day
77
+ '2019-12-25', #Christmas Day
78
+
79
+ '2020-01-01', #New Year’s Day
80
+ '2020-01-20', #Birthday of Martin Luther King, Jr.
81
+ '2020-02-17', #Washington’s Birthday
82
+ '2020-05-25', #Memorial Day
83
+ '2020-07-03', #Independence Day
84
+ '2020-09-07', #Labor Day
85
+ '2020-10-12', #Columbus Day
86
+ '2020-11-11', #Veterans Day
87
+ '2020-11-26', #Thanksgiving Day
88
+ '2020-12-25', #Christmas Day
89
+
90
+ '2021-01-01',
91
+ '2021-01-18',
92
+ '2021-02-15',
93
+ '2021-05-31',
94
+ '2021-07-04',
95
+ '2021-09-06',
96
+ '2021-10-11',
97
+ '2021-11-11',
98
+ '2021-11-25',
99
+ '2021-12-25'
100
+
101
+ ].map {|date_str| Date.parse(date_str) }
102
+ }
103
+
104
+ before :each do
105
+ allow(::UsBankHolidays).to receive(:saturday_holiday_date_rolling?).and_return(true)
102
106
  end
103
107
 
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
108
+ describe '.bank_holiday?' do
109
+ it 'should determine bank holidays on the list' do
110
+ sample_holidays.each { |holiday|
111
+ UsBankHolidays.bank_holiday?(holiday).should eq(true)
112
+ UsBankHolidays.banking_day?(holiday).should eq(false)
113
+ }
114
+ end
109
115
 
110
- it 'regular days should not be bank holidays' do
111
- sample_weekdays.each { |day|
112
- UsBankHolidays.bank_holiday?(day).should be_false
113
- UsBankHolidays.banking_day?(day).should be_true
114
- }
115
- end
116
- end
116
+ it 'weekends should be bank holidays' do
117
+ sample_weekends.each { |weekend|
118
+ UsBankHolidays.bank_holiday?(weekend).should eq(true)
119
+ UsBankHolidays.banking_day?(weekend).should eq(false)
120
+ }
121
+ end
117
122
 
118
- describe '.weekend?' do
119
- it 'should recognize weekends' do
120
- sample_weekends.each { |weekend|
121
- UsBankHolidays.weekend?(weekend).should be_true
122
- UsBankHolidays.banking_day?(weekend).should be_false
123
- }
124
- end
123
+ it 'should exclude weekends if the appropriate flag is passed' do
124
+ sample_weekends.each { |weekend|
125
+ UsBankHolidays.bank_holiday?(weekend, false).should eq(false)
126
+ }
127
+ end
125
128
 
126
- it 'weekdays should not be considered weekends' do
127
- sample_weekdays.each { |day| UsBankHolidays.weekend?(day).should be_false }
129
+ it 'regular days should not be bank holidays' do
130
+ sample_weekdays.each { |day|
131
+ UsBankHolidays.bank_holiday?(day).should eq(false)
132
+ UsBankHolidays.banking_day?(day).should eq(true)
133
+ }
134
+ end
128
135
  end
129
- end
130
-
131
- describe ::UsBankHolidays::DateMethods do
132
136
 
133
137
  describe '.weekend?' do
134
-
135
138
  it 'should recognize weekends' do
136
139
  sample_weekends.each { |weekend|
137
- weekend.weekend?.should be_true
138
- weekend.banking_day?.should be_false
140
+ UsBankHolidays.weekend?(weekend).should eq(true)
141
+ UsBankHolidays.banking_day?(weekend).should eq(false)
139
142
  }
140
143
  end
141
144
 
142
145
  it 'weekdays should not be considered weekends' do
143
- sample_weekdays.each { |day|
144
- day.weekend?.should be_false
145
- day.banking_day?.should be_true
146
- }
146
+ sample_weekdays.each { |day| UsBankHolidays.weekend?(day).should eq(false) }
147
147
  end
148
-
149
148
  end
150
149
 
151
- describe '.bank_holiday?' do
150
+ describe ::UsBankHolidays::DateMethods do
152
151
 
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
152
+ describe '.weekend?' do
159
153
 
160
- it 'should treat weekends as bank holidays' do
161
- sample_weekends.each { |weekend| weekend.bank_holiday?.should be_true }
162
- end
154
+ it 'should recognize weekends' do
155
+ sample_weekends.each { |weekend|
156
+ weekend.weekend?.should eq(true)
157
+ weekend.banking_day?.should eq(false)
158
+ }
159
+ end
163
160
 
164
- it 'should exclude weekends if the appropriate flag is passed' do
165
- sample_weekends.each { |weekend|
166
- weekend.weekend?.should be_true
167
- weekend.bank_holiday?(false).should be_false
168
- }
169
- end
161
+ it 'weekdays should not be considered weekends' do
162
+ sample_weekdays.each { |day|
163
+ day.weekend?.should eq(false)
164
+ day.banking_day?.should eq(true)
165
+ }
166
+ end
170
167
 
171
- it 'should not treat regular weekdays as bank holidays' do
172
- sample_weekdays.each { |day|
173
- day.bank_holiday?.should be_false
174
- day.banking_day?.should be_true
175
- }
176
168
  end
177
169
 
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
170
+ describe '.bank_holiday?' do
171
+
172
+ it 'should recognize bank holidays' do
173
+ sample_holidays.each { |holiday|
174
+ holiday.bank_holiday?.should eq(true)
175
+ holiday.banking_day?.should eq(false)
176
+ }
177
+ end
178
+
179
+ it 'should treat weekends as bank holidays' do
180
+ sample_weekends.each { |weekend| weekend.bank_holiday?.should eq(true) }
181
+ end
182
+
183
+ it 'should exclude weekends if the appropriate flag is passed' do
184
+ sample_weekends.each { |weekend|
185
+ weekend.weekend?.should eq(true)
186
+ weekend.bank_holiday?(false).should eq(false)
187
+ }
188
+ end
189
+
190
+ it 'should not treat regular weekdays as bank holidays' do
191
+ sample_weekdays.each { |day|
192
+ day.bank_holiday?.should eq(false)
193
+ day.banking_day?.should eq(true)
194
+ }
195
+ end
196
+
197
+ it 'if Jan. 1 falls on a Saturday, Dec. 31 of the previous year should be a bank holiday' do
198
+ Date.new(2021, 12, 31).bank_holiday?.should eq(true)
199
+ end
180
200
  end
181
- end
182
201
 
183
- describe '.next_banking_day' do
184
- it 'should determine the next banking day' do
185
- Date.new(2014, 1, 1).next_banking_day.should == Date.new(2014, 1, 2)
186
- Date.new(2014, 1, 2).next_banking_day.should == Date.new(2014, 1, 3)
187
- Date.new(2014, 1, 3).next_banking_day.should == Date.new(2014, 1, 6)
188
- Date.new(2014, 1, 4).next_banking_day.should == Date.new(2014, 1, 6)
189
- Date.new(2014, 1, 5).next_banking_day.should == Date.new(2014, 1, 6)
202
+ describe '.next_banking_day' do
203
+ it 'should determine the next banking day' do
204
+ Date.new(2014, 1, 1).next_banking_day.should == Date.new(2014, 1, 2)
205
+ Date.new(2014, 1, 2).next_banking_day.should == Date.new(2014, 1, 3)
206
+ Date.new(2014, 1, 3).next_banking_day.should == Date.new(2014, 1, 6)
207
+ Date.new(2014, 1, 4).next_banking_day.should == Date.new(2014, 1, 6)
208
+ Date.new(2014, 1, 5).next_banking_day.should == Date.new(2014, 1, 6)
209
+ end
190
210
  end
191
- end
192
211
 
193
- describe '.previous_baking_day' do
194
- it 'should determine the previous banking day' do
195
- Date.new(2014, 1, 7).previous_banking_day.should == Date.new(2014, 1, 6)
196
- Date.new(2014, 1, 6).previous_banking_day.should == Date.new(2014, 1, 3)
197
- Date.new(2014, 1, 5).previous_banking_day.should == Date.new(2014, 1, 3)
198
- Date.new(2014, 1, 4).previous_banking_day.should == Date.new(2014, 1, 3)
199
- Date.new(2014, 1, 21).previous_banking_day.should == Date.new(2014, 1, 17)
212
+ describe '.previous_baking_day' do
213
+ it 'should determine the previous banking day' do
214
+ Date.new(2014, 1, 7).previous_banking_day.should == Date.new(2014, 1, 6)
215
+ Date.new(2014, 1, 6).previous_banking_day.should == Date.new(2014, 1, 3)
216
+ Date.new(2014, 1, 5).previous_banking_day.should == Date.new(2014, 1, 3)
217
+ Date.new(2014, 1, 4).previous_banking_day.should == Date.new(2014, 1, 3)
218
+ Date.new(2014, 1, 21).previous_banking_day.should == Date.new(2014, 1, 17)
219
+ end
200
220
  end
201
- end
202
221
 
203
- describe '.add_banking_days' do
204
- it 'should return self if given 0' do
205
- Date.new(2014, 1, 7).add_banking_days(0).should == Date.new(2014, 1, 7)
206
- end
222
+ describe '.add_banking_days' do
223
+ it 'should return self if given 0' do
224
+ Date.new(2014, 1, 7).add_banking_days(0).should == Date.new(2014, 1, 7)
225
+ end
226
+
227
+ it 'should return self if given 0 even if self is a bank holiday' do
228
+ Date.new(2014, 1, 4).add_banking_days(0).should == Date.new(2014, 1, 4)
229
+ end
207
230
 
208
- it 'should return self if given 0 even if self is a bank holiday' do
209
- Date.new(2014, 1, 4).add_banking_days(0).should == Date.new(2014, 1, 4)
231
+ it 'if given a positive number, should add banking days, ignoring bank holidays' do
232
+ Date.new(2014, 1, 16).add_banking_days(2).should == Date.new(2014, 1, 21)
233
+ end
234
+
235
+ it 'if given a negative number, should subtract banking days, ignoring bank holidays' do
236
+ Date.new(2014, 1, 21).add_banking_days(-2).should == Date.new(2014, 1, 16)
237
+ end
210
238
  end
211
239
 
212
- it 'if given a positive number, should add banking days, ignoring bank holidays' do
213
- Date.new(2014, 1, 16).add_banking_days(2).should == Date.new(2014, 1, 21)
240
+ describe '.last_banking_day_of_month?' do
241
+ it 'should determine if a date is the last banking day of the month' do
242
+ Date.new(2014, 1, 31).last_banking_day_of_month?.should eq(true)
243
+ Date.new(2014, 1, 30).last_banking_day_of_month?.should eq(false)
244
+
245
+ Date.new(2014, 11, 30).last_banking_day_of_month?.should eq(false)
246
+ Date.new(2014, 11, 28).last_banking_day_of_month?.should eq(true)
247
+ end
214
248
  end
215
249
 
216
- it 'if given a negative number, should subtract banking days, ignoring bank holidays' do
217
- Date.new(2014, 1, 21).add_banking_days(-2).should == Date.new(2014, 1, 16)
250
+ describe '.first_banking_day_of_month?' do
251
+ it 'should determine if the date if the first banking day of the month' do
252
+ Date.new(2014, 4, 1).first_banking_day_of_month?.should eq(true)
253
+ Date.new(2014, 4, 2).first_banking_day_of_month?.should eq(false)
254
+
255
+ Date.new(2014, 6, 1).first_banking_day_of_month?.should eq(false)
256
+ Date.new(2014, 6, 2).first_banking_day_of_month?.should eq(true)
257
+ end
218
258
  end
219
259
  end
220
260
  end
261
+
262
+ context "no saturday holiday date rolling" do
263
+
264
+ before :each do
265
+ allow(::UsBankHolidays).to receive(:saturday_holiday_date_rolling?).and_return(false)
266
+ end
267
+
268
+ let(:banking_days) {
269
+ [
270
+ '2021-06-18',
271
+ '2021-12-31'
272
+ ].map {|date_str| Date.parse(date_str) }
273
+ }
274
+
275
+ specify 'banking days' do
276
+ banking_days.each { |date|
277
+ UsBankHolidays.bank_holiday?(date).should eq(false)
278
+ UsBankHolidays.banking_day?(date).should eq(true)
279
+ }
280
+ end
281
+ end
221
282
  end
@@ -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', '~> 1.3'
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.5
4
+ version: 0.2.1
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-24 00:00:00.000000000 Z
11
+ date: 2021-11-18 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: '1.3'
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: '1.3'
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.1.11
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.