business-days 3.1.3 → 3.1.4
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 +19 -0
- 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: a0c1a113899eb0ef5659e2103ff90c391eb161d124db444fe21cbebb4885cb18
|
4
|
+
data.tar.gz: 12ae667e4f542e33230b6b86be1ecc526beb8b81cc238121ac4d0e794d5b85c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4fdc0b05efc376817fb1ec0340ae9e9ab8655e2988eeddc41e87a2d87d180271fa7f1bd5820795f7c5681a70368d51fc9b09b464adbe18f96ccd7994bb55e95
|
7
|
+
data.tar.gz: 79bbd734e3e885af5d9a2c670fb70756ed8b3d1d075dedeb3d5f6bf68b6f6345322c2582053ddf0c0657e1bc23d78ee14aacb755c6b89e1bdab40936449c2ae6
|
data/lib/business-days.rb
CHANGED
@@ -56,6 +56,25 @@ class BusinessDaysSingleton
|
|
56
56
|
(date.to_time.utc.midnight - offset.to_i.hours)
|
57
57
|
end
|
58
58
|
|
59
|
+
# Count business days between two dates.
|
60
|
+
#
|
61
|
+
# @param from [Date] the starting date (inclusive)
|
62
|
+
# @param to [Date] the ending date (inclusive)
|
63
|
+
|
64
|
+
# @return [Integer] number of business days between the two dates
|
65
|
+
def business_days(from, to)
|
66
|
+
raise ArgumentError.new('Not a date: from') unless from.kind_of?(Date)
|
67
|
+
raise ArgumentError.new('Not a date: to') unless to.kind_of?(Date)
|
68
|
+
count = 0
|
69
|
+
|
70
|
+
while from <= to
|
71
|
+
count +=1 if self.business_day?(from)
|
72
|
+
from = from + 1.day
|
73
|
+
end
|
74
|
+
|
75
|
+
count
|
76
|
+
end
|
77
|
+
|
59
78
|
# Check if the given date is a business day
|
60
79
|
#
|
61
80
|
# @param date [Date] the non-business date to be add.
|
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.4
|
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: 2021-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|