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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/business-days.rb +19 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c0bf45b7be3c9886a729b5d860ea5e77bf34741168cf5b0567ce35feddd833f
4
- data.tar.gz: b83d5ce82cb80fea5921f61e1e6a9272dc463921742338a2256bab9f08b605a3
3
+ metadata.gz: a0c1a113899eb0ef5659e2103ff90c391eb161d124db444fe21cbebb4885cb18
4
+ data.tar.gz: 12ae667e4f542e33230b6b86be1ecc526beb8b81cc238121ac4d0e794d5b85c3
5
5
  SHA512:
6
- metadata.gz: ac61b432a5bd0212e248bb8f36d08c1bb97068be2a03e6e10547a6f0fd6c4beaf3423f850e4ab32417223d4ca89dd15962cb93d2ca5839054c87e83bf9d416c8
7
- data.tar.gz: b9dcc655b5bf75b9dc0257732a826aea4cf82d76f54f5bd09678a21943e027a7c0e9aa43bfc7013d77fc060f8e527bb9f8d801a2a2046b0441455079b5bcbf86
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.3
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: 2020-01-04 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport