ae_bank_days 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c8c8214bf575247e58e212562fff3969e708b4d83f34b623a5878fdacce4aa6d
4
+ data.tar.gz: '093a90fecc21551047a56b4246f501a100c8a0bd57c487068dbbeeedce2e37da'
5
+ SHA512:
6
+ metadata.gz: da7ecfb9e25139e038024ab40c8532aa6fc168d4ed50504a75b89f92e71060702cd0282c7f3dd96738c65193e3696c6284afa5c0aa61cd930995a55b0dd198c9
7
+ data.tar.gz: 8266ce73655cb532dda19308adca0c0427a75a9cf657ed2f5bcb18ccc362785fd53e992bfb76122d3f9f1d21f690686c5680fbcb7bc9c896320c2445e2b7fc6c
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ae_bank_days (0.0.1)
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
@@ -0,0 +1,20 @@
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.
@@ -0,0 +1,17 @@
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.
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts 'Run `bundle install` to install missing gems'
10
+ exit e.status_code
11
+ end
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |test|
15
+ test.libs << 'test'
16
+ test.pattern = 'test/**/*_test.rb'
17
+ test.verbose = true
18
+ end
19
+
20
+ task default: :test
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ae_bank_days/version'
6
+
7
+ 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'
18
+
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']
22
+
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']
27
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ae_bank_days/version'
4
+ require 'holidays'
5
+ require 'active_support'
6
+ require 'active_support/core_ext/time'
7
+ require 'active_support/core_ext/integer/time'
8
+
9
+ 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
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AeBankDays
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,42 @@
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
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ae_bank_days
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - AppFolio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-07 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: holidays
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !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: ''
76
+ email:
77
+ - dev@appfolio.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.rdoc
86
+ - Rakefile
87
+ - ae_bank_days.gemspec
88
+ - lib/ae_bank_days.rb
89
+ - lib/ae_bank_days/version.rb
90
+ - test/bank_day_helper_test.rb
91
+ homepage: http://github.com/appfolio/ae_bank_days
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ allowed_push_host: https://rubygems.org
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.3.3
105
+ - - "<"
106
+ - !ruby/object:Gem::Version
107
+ version: '2.7'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.4
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Gem for finding the next banking date
118
+ test_files:
119
+ - test/bank_day_helper_test.rb