ae_bank_days 1.0.0 → 1.3.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: 36bfedfe987fca5f33d94432a975911c86c7059e5ebd8ed043c63e3ba1fb79d9
4
+ data.tar.gz: 97e533307630017923b3be98066497cc9f8ef839681ac0b556bf57aad03ea118
5
5
  SHA512:
6
- metadata.gz: c2300eeb5b2ff561a1b2ea0bbdbfdc597b894e1dc35144ae293b2506fad1df7ebeceb4f5bb44d5acb348887323b5bf35210fc4042014f35fd8496d5b7e54bf7b
7
- data.tar.gz: f02b5860c146c4d3d4590213a6465a898012f2355682f24c915e1bbcfece807e360443ec7d60fae88d19a3925c6f43cfaa70a1dbc565c39aadf9cb2ab1d1d84b
6
+ metadata.gz: 5953980f703d5a2693692712d4d1b3ff4a4c6f4e5805c838447dc3dc4215fd74f56e975d47079fa4add65c41ac8d43c57820918d07ffede9f192f0d44f6e4717
7
+ data.tar.gz: 02dbe2927e5da4c4c1bb4f5b9159cefcaaabbccd608f0122aa8d8bd8e0a1d50f4181ac59f93cf21a40a11572c641176771af35c39ae7e9e00199597e18e1f76d
data/Gemfile CHANGED
@@ -1,5 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source 'https://rubygems.org' do
4
+ gem 'appraisal', '>= 2.3', '< 3'
5
+ gem 'bundler', '>= 1.10.4', '< 3'
6
+ gem 'minitest', '>= 5.8', '< 6'
7
+ gem 'minitest-reporters', '>= 1.4', '< 2'
8
+ gem 'mocha', '>= 1.11', '< 2'
9
+ gem 'rake', '>= 13', '< 14'
10
+ gem 'simplecov', '>= 0.18', '< 1', group: :test, require: false
11
+ end
4
12
 
5
13
  gemspec
@@ -0,0 +1,25 @@
1
+ # AeBankDays
2
+
3
+ Simple utility to find the next banking day
4
+
5
+ ## Running Tests
6
+
7
+ Use the appraisal gem to test different versions of Ruby to ensure changes are compatible. Run them with the
8
+ following command with the different versions of Ruby set:
9
+
10
+ `bundle exec appraisal rake test`
11
+
12
+ For a more detailed output that includes total coverage use:
13
+
14
+ `WITH_COVERAGE=true bundle exec rake test`
15
+
16
+ ## Contributing to AeBankDays
17
+
18
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
19
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
20
+ * Fork the project.
21
+ * Start a feature/bugfix branch.
22
+ * Commit and push until you are happy with your contribution.
23
+ * Make sure to add tests for it. This is important so it doesn't break in a future version unintentionally.
24
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise
25
+ necessary, that is fine, but please isolate to its own commit so it can be cherry-picked around.
data/Rakefile CHANGED
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
3
  require 'bundler'
4
+
5
5
  begin
6
6
  Bundler.setup(:default, :development)
7
7
  rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts 'Run `bundle install` to install missing gems'
8
+ warn e.message
9
+ warn 'Run `bundle install` to install missing gems'
10
10
  exit e.status_code
11
11
  end
12
+
12
13
  require 'rake/testtask'
13
14
 
14
15
  Rake::TestTask.new(:test) do |test|
@@ -1,27 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'ae_bank_days/version'
3
+ require_relative 'lib/ae_bank_days/version'
6
4
 
7
5
  Gem::Specification.new do |spec|
8
- spec.name = 'ae_bank_days'
9
- spec.version = AeBankDays::VERSION
10
- spec.authors = ['AppFolio']
11
- spec.email = ['dev@appfolio.com']
12
- spec.summary = 'Gem for finding the next banking date'
13
- spec.description = ''
14
- spec.homepage = 'http://github.com/appfolio/ae_bank_days'
15
- spec.required_ruby_version = ['>= 2.3.3', '< 2.7']
16
- spec.licenses = ['MIT']
17
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
6
+ spec.name = 'ae_bank_days'
7
+ spec.version = AeBankDays::VERSION
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.authors = ['AppFolio']
10
+ spec.email = ['dev@appfolio.com']
11
+ spec.summary = 'Gem for finding the next banking date'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/appfolio/ae_bank_days'
14
+ spec.required_ruby_version = '>= 2.3.3'
15
+ spec.licenses = ['MIT']
16
+ spec.files = Dir['**/*'].select { |f| f[%r{^(lib/|Gemfile$|Rakefile|README.md|.*gemspec)}] }
17
+ spec.test_files = spec.files.grep(%r{^(test)/})
18
+ spec.require_paths = ['lib']
18
19
 
19
- spec.files = Dir['**/*'].reject { |f| f[%r{^log/}] || f[%r{^pkg/}] }
20
- spec.test_files = spec.files.grep(%r{^(test)/})
21
- spec.require_paths = ['lib']
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
21
 
23
- spec.add_dependency 'activesupport', '< 5.3'
24
- spec.add_dependency 'holidays', '~> 7.1'
25
- spec.add_development_dependency 'rake', '~> 12.0'
26
- spec.add_development_dependency 'bundler', ['>= 1.10.4', '< 2.1']
22
+ spec.add_dependency('holidays', '~> 8.3')
27
23
  end
@@ -1,36 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ae_bank_days/version'
3
+ require 'date'
4
4
  require 'holidays'
5
- require 'active_support'
6
- require 'active_support/core_ext/time'
7
- require 'active_support/core_ext/integer/time'
8
5
 
9
6
  module AeBankDays
10
- class BankDayHelper
11
- # second * minutes * days * years
12
- ten_years_from_now = Time.now + 10.years
13
- HOLIDAYS = Holidays.between(Date.civil(2014, 1, 1), ten_years_from_now, :federalreserve, :observed).map do |holiday|
14
- holiday[:date]
15
- end
16
-
17
- class << self
18
- def bank_day?(day)
19
- date = day.to_date
20
- weekday?(date) && !HOLIDAYS.include?(date)
21
- end
22
-
23
- def next_banking_day(date)
24
- banking_day = date
25
- banking_day += 1 until bank_day?(banking_day)
26
- banking_day
27
- end
28
-
29
- private
30
-
31
- def weekday?(day)
32
- [1, 2, 3, 4, 5].include? day.wday
33
- end
34
- end
35
- end
7
+ autoload :BankDayHelper, 'ae_bank_days/bank_day_helper'
8
+ autoload :DateExtensions, 'ae_bank_days/date_extensions'
36
9
  end
10
+
11
+ Date.send :include, AeBankDays::DateExtensions
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AeBankDays
4
+ class BankDayHelper
5
+ class << self
6
+ Holidays.cache_between(Date.today.prev_year, Date.today.next_year(10), :federalreservebanks, :observed)
7
+
8
+ def bank_day?(day)
9
+ date = day.to_date
10
+ weekday?(date) && Holidays.on(date, :federalreservebanks, :observed).empty?
11
+ end
12
+
13
+ def next_banking_day(date, number_of_days: 0)
14
+ banking_day = date
15
+ number_of_days.times do
16
+ banking_day += 1 until bank_day?(banking_day)
17
+ banking_day += 1
18
+ end
19
+ banking_day += 1 until bank_day?(banking_day)
20
+ banking_day
21
+ end
22
+
23
+ def previous_banking_day(date, number_of_days: 0)
24
+ banking_day = date
25
+ number_of_days.times do
26
+ banking_day -= 1 until bank_day?(banking_day)
27
+ banking_day -= 1
28
+ end
29
+ banking_day -= 1 until bank_day?(banking_day)
30
+ banking_day
31
+ end
32
+
33
+ private
34
+
35
+ def weekday?(day)
36
+ (1..5).include?(day.wday)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AeBankDays
4
- VERSION = '1.0.0'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,78 +1,30 @@
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.3.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: 2019-11-07 00:00:00.000000000 Z
11
+ date: 2020-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: '5.3'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "<"
25
- - !ruby/object:Gem::Version
26
- version: '5.3'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: holidays
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '7.1'
19
+ version: '8.3'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '7.1'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '12.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '12.0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 1.10.4
62
- - - "<"
63
- - !ruby/object:Gem::Version
64
- version: '2.1'
65
- type: :development
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- version: 1.10.4
72
- - - "<"
73
- - !ruby/object:Gem::Version
74
- version: '2.1'
75
- description: ''
26
+ version: '8.3'
27
+ description: Gem for finding the next banking date
76
28
  email:
77
29
  - dev@appfolio.com
78
30
  executables: []
@@ -80,20 +32,19 @@ extensions: []
80
32
  extra_rdoc_files: []
81
33
  files:
82
34
  - Gemfile
83
- - Gemfile.lock
84
- - LICENSE.txt
85
- - README.rdoc
35
+ - README.md
86
36
  - Rakefile
87
37
  - ae_bank_days.gemspec
88
38
  - lib/ae_bank_days.rb
39
+ - lib/ae_bank_days/bank_day_helper.rb
40
+ - lib/ae_bank_days/date_extensions.rb
89
41
  - lib/ae_bank_days/version.rb
90
- - test/bank_day_helper_test.rb
91
- homepage: http://github.com/appfolio/ae_bank_days
42
+ homepage: https://github.com/appfolio/ae_bank_days
92
43
  licenses:
93
44
  - MIT
94
45
  metadata:
95
46
  allowed_push_host: https://rubygems.org
96
- post_install_message:
47
+ post_install_message:
97
48
  rdoc_options: []
98
49
  require_paths:
99
50
  - lib
@@ -102,18 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
53
  - - ">="
103
54
  - !ruby/object:Gem::Version
104
55
  version: 2.3.3
105
- - - "<"
106
- - !ruby/object:Gem::Version
107
- version: '2.7'
108
56
  required_rubygems_version: !ruby/object:Gem::Requirement
109
57
  requirements:
110
58
  - - ">="
111
59
  - !ruby/object:Gem::Version
112
60
  version: '0'
113
61
  requirements: []
114
- rubygems_version: 3.0.4
115
- signing_key:
62
+ rubygems_version: 3.1.2
63
+ signing_key:
116
64
  specification_version: 4
117
65
  summary: Gem for finding the next banking date
118
- test_files:
119
- - test/bank_day_helper_test.rb
66
+ test_files: []
@@ -1,35 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ae_bank_days (1.0.0)
5
- activesupport (< 5.3)
6
- holidays (~> 7.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (5.2.3)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- concurrent-ruby (1.1.5)
17
- holidays (7.1.0)
18
- i18n (1.7.0)
19
- concurrent-ruby (~> 1.0)
20
- minitest (5.13.0)
21
- rake (12.3.2)
22
- thread_safe (0.3.6)
23
- tzinfo (1.2.5)
24
- thread_safe (~> 0.1)
25
-
26
- PLATFORMS
27
- ruby
28
-
29
- DEPENDENCIES
30
- ae_bank_days!
31
- bundler (>= 1.10.4, < 2.1)
32
- rake (~> 12.0)
33
-
34
- BUNDLED WITH
35
- 2.0.2
@@ -1,20 +0,0 @@
1
- Copyright (c) 2019 AppFolio inc
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,17 +0,0 @@
1
- = ae_bank_days
2
-
3
- Simple utility to find the next banking day
4
-
5
- == Contributing to ae_bank_days
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright © 2019 AppFolio.
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'minitest/autorun'
4
- require 'ae_bank_days'
5
-
6
- module AeBankDays
7
- class BankDayHelperTest < ActiveSupport::TestCase
8
- def test_constant
9
- refute AeBankDays::BankDayHelper::HOLIDAYS.empty?
10
- end
11
-
12
- def test_bank_day__weekday
13
- time = Time.parse('2017-10-03 14:30:45 -0500')
14
- assert AeBankDays::BankDayHelper.bank_day?(time.to_date)
15
- end
16
-
17
- def test_bank_day__weekend
18
- time = Time.parse('2017-10-14 14:30:45 -0500')
19
- refute AeBankDays::BankDayHelper.bank_day?(time.to_date)
20
- end
21
-
22
- def test_bank_day__holiday
23
- time = Time.parse('2017-10-09 14:30:45 -0500')
24
- refute AeBankDays::BankDayHelper.bank_day?(time.to_date)
25
- end
26
-
27
- def test_next_banking_day__weekday
28
- time = Time.parse('2017-10-03 14:30:45 -0500')
29
- assert_equal Date.parse('2017-10-03'), AeBankDays::BankDayHelper.next_banking_day(time.to_date)
30
- end
31
-
32
- def test_next_banking_day__weekend
33
- time = Time.parse('2017-10-14 14:30:45 -0500')
34
- assert_equal Date.parse('2017-10-16'), AeBankDays::BankDayHelper.next_banking_day(time.to_date)
35
- end
36
-
37
- def test_next_banking_day__holiday
38
- time = Time.parse('2017-10-09 14:30:45 -0500')
39
- assert_equal Date.parse('2017-10-10'), AeBankDays::BankDayHelper.next_banking_day(time.to_date)
40
- end
41
- end
42
- end