ae_bank_days 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -7
- data/ae_bank_days.gemspec +2 -1
- data/lib/ae_bank_days.rb +3 -0
- data/lib/ae_bank_days/bank_day_helper.rb +3 -7
- data/lib/ae_bank_days/date_extensions.rb +15 -0
- data/lib/ae_bank_days/version.rb +1 -1
- data/test/ae_bank_days/bank_day_helper_test.rb +23 -36
- data/test/ae_bank_days/date_extensions_test.rb +46 -0
- data/test/test_helper.rb +1 -0
- metadata +25 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06f9983d00ce48e33b4a934f726e456d1eb37daec1355aad31cf605f9c5ef0bd
|
4
|
+
data.tar.gz: e3b17132d6696f57e38e2a1addac13d1ae4daa49fcb788dae5e553b66cec463f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f43ac398011e018ece5207f6db467339a3b9255451627cad5cd5e970b3d08512d38c3ae9d09604ddf09d177a30febdbf98d7e5e5ba6ef8329c9122aea7424e8b
|
7
|
+
data.tar.gz: b0e66f75d0ea3c5ac6d39a7240e3a284af57968292e69a5b14dbfb1753273bc21a425ab9b67e0b8f5bcedffd8bc87a7d77cca0959b6944d0a3d75105087a4c00
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ae_bank_days (1.
|
5
|
-
holidays (~>
|
4
|
+
ae_bank_days (1.2.0)
|
5
|
+
holidays (~> 8.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ansi (1.5.0)
|
11
|
-
builder (3.2.
|
12
|
-
holidays (
|
13
|
-
minitest (5.
|
11
|
+
builder (3.2.4)
|
12
|
+
holidays (8.3.0)
|
13
|
+
minitest (5.11.3)
|
14
14
|
minitest-reporters (1.3.0)
|
15
15
|
ansi
|
16
16
|
builder
|
17
17
|
minitest (>= 5.0)
|
18
18
|
ruby-progressbar
|
19
|
-
|
19
|
+
mocha (1.11.2)
|
20
|
+
rake (12.3.3)
|
20
21
|
ruby-progressbar (1.10.1)
|
21
22
|
|
22
23
|
PLATFORMS
|
@@ -27,7 +28,8 @@ DEPENDENCIES
|
|
27
28
|
bundler (>= 1.10.4, < 3)
|
28
29
|
minitest (>= 5.8)
|
29
30
|
minitest-reporters (>= 1.3)
|
31
|
+
mocha (>= 1.1)
|
30
32
|
rake (>= 12.0)
|
31
33
|
|
32
34
|
BUNDLED WITH
|
33
|
-
2.
|
35
|
+
2.1.4
|
data/ae_bank_days.gemspec
CHANGED
@@ -21,10 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
23
23
|
|
24
|
-
spec.add_dependency('holidays', '~>
|
24
|
+
spec.add_dependency('holidays', '~> 8.3')
|
25
25
|
|
26
26
|
spec.add_development_dependency('bundler', ['>= 1.10.4', '< 3'])
|
27
27
|
spec.add_development_dependency('minitest', '>= 5.8')
|
28
28
|
spec.add_development_dependency('minitest-reporters', '>= 1.3')
|
29
|
+
spec.add_development_dependency('mocha', '>= 1.1')
|
29
30
|
spec.add_development_dependency('rake', '>= 12.0')
|
30
31
|
end
|
data/lib/ae_bank_days.rb
CHANGED
@@ -2,16 +2,12 @@
|
|
2
2
|
|
3
3
|
module AeBankDays
|
4
4
|
class BankDayHelper
|
5
|
-
START_DATE = Date.civil(2014, 1, 1)
|
6
|
-
END_DATE = Date.today.next_year(10)
|
7
|
-
HOLIDAYS = Holidays.between(START_DATE, END_DATE, :federalreserve, :observed).map do |holiday|
|
8
|
-
holiday[:date]
|
9
|
-
end
|
10
|
-
|
11
5
|
class << self
|
6
|
+
Holidays.cache_between(Date.today.prev_year, Date.today.next_year(10), :federalreservebanks, :observed)
|
7
|
+
|
12
8
|
def bank_day?(day)
|
13
9
|
date = day.to_date
|
14
|
-
weekday?(date) &&
|
10
|
+
weekday?(date) && Holidays.on(date, :federalreservebanks, :observed).empty?
|
15
11
|
end
|
16
12
|
|
17
13
|
def next_banking_day(date, number_of_days: 0)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AeBankDays
|
2
|
+
module DateExtensions
|
3
|
+
def bank_day?
|
4
|
+
BankDayHelper.bank_day?(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def next_banking_day(n = 0)
|
8
|
+
BankDayHelper.next_banking_day(self, number_of_days: n)
|
9
|
+
end
|
10
|
+
|
11
|
+
def previous_banking_day(n = 0)
|
12
|
+
BankDayHelper.previous_banking_day(self, number_of_days: n)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/ae_bank_days/version.rb
CHANGED
@@ -4,85 +4,72 @@ require 'test_helper'
|
|
4
4
|
|
5
5
|
module AeBankDays
|
6
6
|
class BankDayHelperTest < Minitest::Test
|
7
|
-
def test_constants
|
8
|
-
assert_equal Date.civil(2014, 1, 1), BankDayHelper::START_DATE
|
9
|
-
assert_equal Date.today.next_year(10), BankDayHelper::END_DATE
|
10
|
-
assert BankDayHelper::HOLIDAYS.any?
|
11
|
-
end
|
12
|
-
|
13
7
|
def test_bank_day__weekday
|
14
|
-
|
15
|
-
assert BankDayHelper.bank_day?(time.to_date)
|
8
|
+
assert BankDayHelper.bank_day?(Date.civil(2017, 10, 3))
|
16
9
|
end
|
17
10
|
|
18
11
|
def test_bank_day__weekend
|
19
|
-
|
20
|
-
refute BankDayHelper.bank_day?(time.to_date)
|
12
|
+
refute BankDayHelper.bank_day?(Date.civil(2017, 10, 14))
|
21
13
|
end
|
22
14
|
|
23
15
|
def test_bank_day__holiday
|
24
|
-
|
25
|
-
|
16
|
+
refute BankDayHelper.bank_day?(Date.civil(2017, 10, 9))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_bank_day__saturday_holiday_is_not_observed_on_friday
|
20
|
+
# The federal bank does not observe holidays that fall on Saturday on the preceding Friday as is common.
|
21
|
+
# This test makes sure that these dates are not accidentally marked as holidays.
|
22
|
+
# July 4, 2020 fell on a Saturday. The day before was a generally observed federal holiday, but it was still
|
23
|
+
# a banking day due to the federal banks holiday rules.
|
24
|
+
assert BankDayHelper.bank_day?(Date.civil(2020, 6, 3))
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_next_banking_day__weekday
|
29
|
-
|
30
|
-
assert_equal Date.parse('2017-10-03'), BankDayHelper.next_banking_day(time.to_date)
|
28
|
+
assert_equal Date.civil(2017, 10, 3), BankDayHelper.next_banking_day(Date.civil(2017, 10, 3))
|
31
29
|
end
|
32
30
|
|
33
31
|
def test_next_banking_day__weekday__extra_days
|
34
|
-
|
35
|
-
assert_equal Date.parse('2017-10-06'), BankDayHelper.next_banking_day(time.to_date, number_of_days: 3)
|
32
|
+
assert_equal Date.civil(2017, 10, 6), BankDayHelper.next_banking_day(Date.civil(2017, 10, 3), number_of_days: 3)
|
36
33
|
end
|
37
34
|
|
38
35
|
def test_next_banking_day__weekend
|
39
|
-
|
40
|
-
assert_equal Date.parse('2017-10-16'), BankDayHelper.next_banking_day(time.to_date)
|
36
|
+
assert_equal Date.civil(2017, 10, 16), BankDayHelper.next_banking_day(Date.civil(2017, 10, 14))
|
41
37
|
end
|
42
38
|
|
43
39
|
def test_next_banking_day__weekend__extra_days
|
44
|
-
|
45
|
-
assert_equal Date.parse('2017-10-19'), BankDayHelper.next_banking_day(time.to_date, number_of_days: 3)
|
40
|
+
assert_equal Date.civil(2017, 10, 19), BankDayHelper.next_banking_day(Date.civil(2017, 10, 14), number_of_days: 3)
|
46
41
|
end
|
47
42
|
|
48
43
|
def test_next_banking_day__holiday
|
49
|
-
|
50
|
-
assert_equal Date.parse('2017-10-10'), BankDayHelper.next_banking_day(time.to_date)
|
44
|
+
assert_equal Date.civil(2017, 10, 10), BankDayHelper.next_banking_day(Date.civil(2017, 10, 9))
|
51
45
|
end
|
52
46
|
|
53
47
|
def test_next_banking_day__holiday__extra_days
|
54
|
-
|
55
|
-
assert_equal Date.parse('2017-10-13'), BankDayHelper.next_banking_day(time.to_date, number_of_days: 3)
|
48
|
+
assert_equal Date.civil(2017, 10, 13), BankDayHelper.next_banking_day(Date.civil(2017, 10, 9), number_of_days: 3)
|
56
49
|
end
|
57
50
|
|
58
51
|
def test_previous_banking_day__weekday
|
59
|
-
|
60
|
-
assert_equal Date.parse('2017-10-03'), BankDayHelper.previous_banking_day(time.to_date)
|
52
|
+
assert_equal Date.civil(2017, 10, 3), BankDayHelper.previous_banking_day(Date.civil(2017, 10, 3))
|
61
53
|
end
|
62
54
|
|
63
55
|
def test_previous_banking_day__weekday__extra_days
|
64
|
-
|
65
|
-
assert_equal Date.parse('2017-10-03'), BankDayHelper.previous_banking_day(time.to_date, number_of_days: 3)
|
56
|
+
assert_equal Date.civil(2017, 10, 3), BankDayHelper.previous_banking_day(Date.civil(2017, 10, 6), number_of_days: 3)
|
66
57
|
end
|
67
58
|
|
68
59
|
def test_previous_banking_day__weekend
|
69
|
-
|
70
|
-
assert_equal Date.parse('2017-10-13'), BankDayHelper.previous_banking_day(time.to_date)
|
60
|
+
assert_equal Date.civil(2017, 10, 13), BankDayHelper.previous_banking_day(Date.civil(2017, 10, 14))
|
71
61
|
end
|
72
62
|
|
73
63
|
def test_previous_banking_day__weekend__extra_days
|
74
|
-
|
75
|
-
assert_equal Date.parse('2017-10-10'), BankDayHelper.previous_banking_day(time.to_date, number_of_days: 3)
|
64
|
+
assert_equal Date.civil(2017, 10, 10), BankDayHelper.previous_banking_day(Date.civil(2017, 10, 14), number_of_days: 3)
|
76
65
|
end
|
77
66
|
|
78
67
|
def test_previous_banking_day__holiday
|
79
|
-
|
80
|
-
assert_equal Date.parse('2017-10-06'), BankDayHelper.previous_banking_day(time.to_date)
|
68
|
+
assert_equal Date.civil(2017, 10, 6), BankDayHelper.previous_banking_day(Date.civil(2017, 10, 9))
|
81
69
|
end
|
82
70
|
|
83
71
|
def test_previous_banking_day__holiday__extra_days
|
84
|
-
|
85
|
-
assert_equal Date.parse('2017-10-03'), BankDayHelper.previous_banking_day(time.to_date, number_of_days: 3)
|
72
|
+
assert_equal Date.civil(2017, 10, 3), BankDayHelper.previous_banking_day(Date.civil(2017, 10, 9), number_of_days: 3)
|
86
73
|
end
|
87
74
|
end
|
88
75
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
module AeBankDays
|
6
|
+
class DateExtensionsTest < Minitest::Test
|
7
|
+
def test_bank_day
|
8
|
+
date = Date.today
|
9
|
+
BankDayHelper.expects(:bank_day?).with(date).returns(true)
|
10
|
+
|
11
|
+
assert date.bank_day?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_next_banking_day
|
15
|
+
date = Date.today
|
16
|
+
new_date = date + 2
|
17
|
+
BankDayHelper.expects(:next_banking_day).with(date, number_of_days: 2).returns(new_date)
|
18
|
+
|
19
|
+
assert_equal new_date, date.next_banking_day(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_next_banking_day__default
|
23
|
+
date = Date.today
|
24
|
+
new_date = date + 2
|
25
|
+
BankDayHelper.expects(:next_banking_day).with(date, number_of_days: 0).returns(new_date)
|
26
|
+
|
27
|
+
assert_equal new_date, date.next_banking_day
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_previous_banking_day
|
31
|
+
date = Date.today
|
32
|
+
new_date = date + 2
|
33
|
+
BankDayHelper.expects(:previous_banking_day).with(date, number_of_days: 2).returns(new_date)
|
34
|
+
|
35
|
+
assert_equal new_date, date.previous_banking_day(2)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_previous_banking_day__default
|
39
|
+
date = Date.today
|
40
|
+
new_date = date + 2
|
41
|
+
BankDayHelper.expects(:previous_banking_day).with(date, number_of_days: 0).returns(new_date)
|
42
|
+
|
43
|
+
assert_equal new_date, date.previous_banking_day
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_bank_days
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AppFolio
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: holidays
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '8.3'
|
20
20
|
type: :runtime
|
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: '8.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '1.3'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: mocha
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.1'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.1'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: rake
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,8 +115,10 @@ files:
|
|
101
115
|
- ae_bank_days.gemspec
|
102
116
|
- lib/ae_bank_days.rb
|
103
117
|
- lib/ae_bank_days/bank_day_helper.rb
|
118
|
+
- lib/ae_bank_days/date_extensions.rb
|
104
119
|
- lib/ae_bank_days/version.rb
|
105
120
|
- test/ae_bank_days/bank_day_helper_test.rb
|
121
|
+
- test/ae_bank_days/date_extensions_test.rb
|
106
122
|
- test/ae_bank_days_test.rb
|
107
123
|
- test/test_helper.rb
|
108
124
|
homepage: http://github.com/appfolio/ae_bank_days
|
@@ -110,7 +126,7 @@ licenses:
|
|
110
126
|
- MIT
|
111
127
|
metadata:
|
112
128
|
allowed_push_host: https://rubygems.org
|
113
|
-
post_install_message:
|
129
|
+
post_install_message:
|
114
130
|
rdoc_options: []
|
115
131
|
require_paths:
|
116
132
|
- lib
|
@@ -128,11 +144,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
144
|
- !ruby/object:Gem::Version
|
129
145
|
version: '0'
|
130
146
|
requirements: []
|
131
|
-
rubygems_version: 3.0.
|
132
|
-
signing_key:
|
147
|
+
rubygems_version: 3.0.3
|
148
|
+
signing_key:
|
133
149
|
specification_version: 4
|
134
150
|
summary: Gem for finding the next banking date
|
135
151
|
test_files:
|
136
152
|
- test/ae_bank_days/bank_day_helper_test.rb
|
153
|
+
- test/ae_bank_days/date_extensions_test.rb
|
137
154
|
- test/ae_bank_days_test.rb
|
138
155
|
- test/test_helper.rb
|