roxbury 0.1.1 → 0.2.1

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: 95a78111c7254e8b3e5f35c69e781f16f971ad839c0e7c76c42b4f41ea681bd7
4
- data.tar.gz: 9d76e376abecaa9796dd40f532b66d69e623876a0efc9360cf70976d4a4a9359
3
+ metadata.gz: '083b94bc5b909ea14a3607950f68fc1cdf22c6319bec0dd97fa8bc125ce8de54'
4
+ data.tar.gz: 464e95eda05d38625f90b7ea63ff38c4554de4045a58cb60e3959337427867e6
5
5
  SHA512:
6
- metadata.gz: db1b169f1db6ce10e4a9831a2400a3ff914f0bb5c7ba31d0bca9527fa144ded503200b78e2583bc1d619337862aa7126134f8cd852a54566c8efaef1f455fc32
7
- data.tar.gz: 12b76c182370f9b382cdb15f73c7eb3afebdf1300c94973fc0bec8d1a56178a280323ac0bd3b2d3ff9ed6908ec6b9d4e13dcf4c59e04759f9f75fb502951a10b
6
+ metadata.gz: e45ddec1a5f4a24a66e171c9d8bff69018ab39a1c67759163f5b352c68be6271e86a424467b343a71ce7f1d14bda57f9c02a41c055cd84eed0ee1c92f233a05f
7
+ data.tar.gz: bdb32f0528ba2d0f2d1408652fa61795bf07935cf8c1b0796495f2720b319cd74aa00a6e1441f8839943c6ada28629ae2431a62cefb9a844a301b915ab1029f6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roxbury (0.1.1)
4
+ roxbury (0.2.1)
5
5
  activesupport (>= 4.2)
6
6
 
7
7
  GEM
@@ -75,7 +75,7 @@ GEM
75
75
  thread_safe (0.3.6)
76
76
  tzinfo (1.2.5)
77
77
  thread_safe (~> 0.1)
78
- zeitwerk (2.1.9)
78
+ zeitwerk (2.1.10)
79
79
 
80
80
  PLATFORMS
81
81
  ruby
@@ -38,7 +38,7 @@ module Roxbury
38
38
 
39
39
  until (bday = business_day(rolling_timestamp)).include?(rolling_timestamp + remaining_hours.hours)
40
40
  remaining_hours -= bday.number_of_working_hours(from: rolling_timestamp)
41
- rolling_timestamp = at_beginning_of_next_business_day(rolling_timestamp)
41
+ rolling_timestamp = next_working_day(rolling_timestamp)
42
42
  end
43
43
 
44
44
  rolling_timestamp + remaining_hours.hours
@@ -64,7 +64,7 @@ module Roxbury
64
64
  remaining_days = number_of_days
65
65
  rolling_date = to
66
66
  loop do
67
- remaining_days -= business_day(rolling_date).number_of_working_hours * 1.0 / max_working_hours_in_a_day
67
+ remaining_days -= working_hours_percentage(rolling_date)
68
68
  break if remaining_days < 0
69
69
  rolling_date = roll_forward rolling_date.next
70
70
  end
@@ -86,9 +86,21 @@ module Roxbury
86
86
  end
87
87
  end
88
88
 
89
- # Snaps the date to the beginning of the next business day.
90
- def at_beginning_of_next_business_day date
91
- roll_forward date.tomorrow.beginning_of_day
89
+ # If a Date is given, returns then next business day.
90
+ # Otherwise if a Time is given, snaps the date to the beginning of the next business day.
91
+ def next_working_day date
92
+ case date
93
+ when Time
94
+ roll_forward date.tomorrow.beginning_of_day
95
+ when Date
96
+ roll_forward date.tomorrow
97
+ else
98
+ raise ArgumentError, 'only Date or Time instances are allowed'
99
+ end
100
+ end
101
+
102
+ def working_hours_percentage date
103
+ business_day(date).number_of_working_hours * 1.0 / max_working_hours_in_a_day
92
104
  end
93
105
 
94
106
  def holiday? date_or_time
@@ -1,3 +1,3 @@
1
1
  module Roxbury
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roxbury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Nicolau
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-28 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport