business-days 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/business-days.rb +21 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d65a0be7582b342cb6bd352d97d5bdfa2c381b28a8d965bc2c8a7310e327a5d
|
4
|
+
data.tar.gz: 6c4895bf46e75de6658bfe874b5642702961ef957d24672985ad75c2059ca149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f59925ea7d0bcfe194e385a2648acbf69f77719d90ec5cac59c9bb9934eabe47044fa7c004189a382837c2afa4f7a2195e41566ba6a798f853aefc5d1b2b3735
|
7
|
+
data.tar.gz: f7e2f7f5b34f709c1a742853feae4cac45d82083fc359d62b3b1de972640c3dcfff77cff4375865b6bd0127f9bf14fba0e71500e72ffb9458bf6ac8d895585b1
|
data/lib/business-days.rb
CHANGED
@@ -25,7 +25,7 @@ class BusinessDaysSingleton
|
|
25
25
|
|
26
26
|
# 3. Add the latest business day in each year (it's a bank holiday)
|
27
27
|
(from..to).each do |year|
|
28
|
-
@holidays.push(
|
28
|
+
@holidays.push(latest_non_bank_business_day(year))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -76,6 +76,24 @@ class BusinessDaysSingleton
|
|
76
76
|
@holidays.push(date)
|
77
77
|
end
|
78
78
|
|
79
|
+
# Remove given date from holidays list for all commands after this.
|
80
|
+
#
|
81
|
+
# @param date [Date] the non-holiday date to be add.
|
82
|
+
def remove_holiday(date)
|
83
|
+
raise ArgumentError.new('Not a date') unless date.kind_of?(Date)
|
84
|
+
|
85
|
+
@holidays.delete(date)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Remove latest holiday for each year
|
89
|
+
def remove_latest_non_bank_business_days
|
90
|
+
years = Set.new(@holidays.map { |d| d.year })
|
91
|
+
years.each do |year|
|
92
|
+
max_date = @holidays.select { |d| d.year == year }.max
|
93
|
+
self.remove_holiday(max_date)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
79
97
|
# Returns the first business day after the given date.
|
80
98
|
#
|
81
99
|
# @param date [Date] the reference date.
|
@@ -105,9 +123,10 @@ class BusinessDaysSingleton
|
|
105
123
|
|
106
124
|
date
|
107
125
|
end
|
126
|
+
|
108
127
|
private
|
109
128
|
|
110
|
-
def
|
129
|
+
def latest_non_bank_business_day(year)
|
111
130
|
d = Date.civil(year, 12, 31)
|
112
131
|
while !self.business_day?(d)
|
113
132
|
d = d - 1.day
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business-days
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allan Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|