ae_bank_days 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b352ad3a4d79adb79d0f9cbdfc6040cd4fe9a5a997d364d81b1a8cafbec27cb8
4
- data.tar.gz: d08d58bacc6ba8b394e90714bcc012c7ea810f92b476bece48d61bcffdbadd4d
3
+ metadata.gz: 01e5531a35c63eae2105cf384eaa798054a373cb5c178ff4e7eed08689d6b473
4
+ data.tar.gz: 8e4a1ae4e93cfa286c4a1705b50f947c39febc33915ea63c9808472d290c477e
5
5
  SHA512:
6
- metadata.gz: c2300eeb5b2ff561a1b2ea0bbdbfdc597b894e1dc35144ae293b2506fad1df7ebeceb4f5bb44d5acb348887323b5bf35210fc4042014f35fd8496d5b7e54bf7b
7
- data.tar.gz: f02b5860c146c4d3d4590213a6465a898012f2355682f24c915e1bbcfece807e360443ec7d60fae88d19a3925c6f43cfaa70a1dbc565c39aadf9cb2ab1d1d84b
6
+ metadata.gz: 23e9526aa06096f527a363f269cb39df391cab9d233ca20407e41de0dbf8afeff89d1ebc727968e592dd6ec009770766ac8d95af7838c3c527a0b12a23afd9bd
7
+ data.tar.gz: c175d76b81a001be7a8b1b105d5c76a58bd4aa6b08e48ffd090aa91f9b7d2274597e8f2a4bd905d4457625d1a932c6311736967b2deb4007f0a2ae4550a0b41d
Binary file
data/lib/ae_bank_days.rb CHANGED
@@ -8,7 +8,6 @@ require 'active_support/core_ext/integer/time'
8
8
 
9
9
  module AeBankDays
10
10
  class BankDayHelper
11
- # second * minutes * days * years
12
11
  ten_years_from_now = Time.now + 10.years
13
12
  HOLIDAYS = Holidays.between(Date.civil(2014, 1, 1), ten_years_from_now, :federalreserve, :observed).map do |holiday|
14
13
  holiday[:date]
@@ -20,12 +19,26 @@ module AeBankDays
20
19
  weekday?(date) && !HOLIDAYS.include?(date)
21
20
  end
22
21
 
23
- def next_banking_day(date)
22
+ def next_banking_day(date, number_of_days: 0)
24
23
  banking_day = date
24
+ number_of_days.times do
25
+ banking_day += 1 until bank_day?(banking_day)
26
+ banking_day += 1
27
+ end
25
28
  banking_day += 1 until bank_day?(banking_day)
26
29
  banking_day
27
30
  end
28
31
 
32
+ def previous_banking_day(date, number_of_days: 0)
33
+ banking_day = date
34
+ number_of_days.times do
35
+ banking_day -= 1 until bank_day?(banking_day)
36
+ banking_day -= 1
37
+ end
38
+ banking_day -= 1 until bank_day?(banking_day)
39
+ banking_day
40
+ end
41
+
29
42
  private
30
43
 
31
44
  def weekday?(day)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AeBankDays
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -29,14 +29,59 @@ module AeBankDays
29
29
  assert_equal Date.parse('2017-10-03'), AeBankDays::BankDayHelper.next_banking_day(time.to_date)
30
30
  end
31
31
 
32
+ def test_next_banking_day__weekday__extra_days
33
+ time = Time.parse('2017-10-03 14:30:45 -0500')
34
+ assert_equal Date.parse('2017-10-06'), AeBankDays::BankDayHelper.next_banking_day(time.to_date, number_of_days: 3)
35
+ end
36
+
32
37
  def test_next_banking_day__weekend
33
38
  time = Time.parse('2017-10-14 14:30:45 -0500')
34
39
  assert_equal Date.parse('2017-10-16'), AeBankDays::BankDayHelper.next_banking_day(time.to_date)
35
40
  end
36
41
 
42
+ def test_next_banking_day__weekend__extra_days
43
+ time = Time.parse('2017-10-14 14:30:45 -0500')
44
+ assert_equal Date.parse('2017-10-19'), AeBankDays::BankDayHelper.next_banking_day(time.to_date, number_of_days: 3)
45
+ end
46
+
37
47
  def test_next_banking_day__holiday
38
48
  time = Time.parse('2017-10-09 14:30:45 -0500')
39
49
  assert_equal Date.parse('2017-10-10'), AeBankDays::BankDayHelper.next_banking_day(time.to_date)
40
50
  end
51
+
52
+ def test_next_banking_day__holiday__extra_days
53
+ time = Time.parse('2017-10-09 14:30:45 -0500')
54
+ assert_equal Date.parse('2017-10-13'), AeBankDays::BankDayHelper.next_banking_day(time.to_date, number_of_days: 3)
55
+ end
56
+
57
+ def test_previous_banking_day__weekday
58
+ time = Time.parse('2017-10-03 14:30:45 -0500')
59
+ assert_equal Date.parse('2017-10-03'), AeBankDays::BankDayHelper.previous_banking_day(time.to_date)
60
+ end
61
+
62
+ def test_previous_banking_day__weekday__extra_days
63
+ time = Time.parse('2017-10-06 14:30:45 -0500')
64
+ assert_equal Date.parse('2017-10-03'), AeBankDays::BankDayHelper.previous_banking_day(time.to_date, number_of_days: 3)
65
+ end
66
+
67
+ def test_previous_banking_day__weekend
68
+ time = Time.parse('2017-10-14 14:30:45 -0500')
69
+ assert_equal Date.parse('2017-10-13'), AeBankDays::BankDayHelper.previous_banking_day(time.to_date)
70
+ end
71
+
72
+ def test_previous_banking_day__weekend__extra_days
73
+ time = Time.parse('2017-10-14 14:30:45 -0500')
74
+ assert_equal Date.parse('2017-10-10'), AeBankDays::BankDayHelper.previous_banking_day(time.to_date, number_of_days: 3)
75
+ end
76
+
77
+ def test_previous_banking_day__holiday
78
+ time = Time.parse('2017-10-09 14:30:45 -0500')
79
+ assert_equal Date.parse('2017-10-06'), AeBankDays::BankDayHelper.previous_banking_day(time.to_date)
80
+ end
81
+
82
+ def test_previous_banking_day__holiday__extra_days
83
+ time = Time.parse('2017-10-09 14:30:45 -0500')
84
+ assert_equal Date.parse('2017-10-03'), AeBankDays::BankDayHelper.previous_banking_day(time.to_date, number_of_days: 3)
85
+ end
41
86
  end
42
87
  end
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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AppFolio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-07 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -84,6 +84,7 @@ files:
84
84
  - LICENSE.txt
85
85
  - README.rdoc
86
86
  - Rakefile
87
+ - ae_bank_days-1.0.0.gem
87
88
  - ae_bank_days.gemspec
88
89
  - lib/ae_bank_days.rb
89
90
  - lib/ae_bank_days/version.rb