biz 1.8.1 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/biz/calculation/for_duration.rb +15 -24
- data/lib/biz/day_time.rb +2 -1
- data/lib/biz/periods/abstract.rb +2 -3
- data/lib/biz/periods/after.rb +0 -4
- data/lib/biz/periods/before.rb +0 -4
- data/lib/biz/time_segment.rb +11 -7
- data/lib/biz/timeline/abstract.rb +13 -6
- data/lib/biz/timeline/backward.rb +6 -2
- data/lib/biz/timeline/forward.rb +6 -2
- data/lib/biz/version.rb +1 -1
- 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: 78100d6bedcc407d7fd7f9d740963d7484e4bc2e211bb4f3d3b2ed8d30e2e85d
|
4
|
+
data.tar.gz: e2a72d2cf20cc430aab2db269d48e025c208da15b54d55afb2c00b08380fb925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0051858f8326ad8a583f98a791babe88999f290fffcf6a8640b345ece04f65b0cab6da496433d7be226e965657234a1bc3375c87f12c5157229fb230b82bbcae'
|
7
|
+
data.tar.gz: 3c2ddad60473deb1a4da239bf0092af9326e08b4a092150c45ca59c4648684250e0b112be09669399482c48f9753518f484fb34b6cdf3e81fcf1a083e60fdce8
|
data/README.md
CHANGED
@@ -341,7 +341,7 @@ To open a console with the gem and sample schedule loaded:
|
|
341
341
|
|
342
342
|
## Copyright and license
|
343
343
|
|
344
|
-
Copyright 2015-
|
344
|
+
Copyright 2015-19 Zendesk
|
345
345
|
|
346
346
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
347
347
|
this gem except in compliance with the License.
|
@@ -25,14 +25,10 @@ module Biz
|
|
25
25
|
def self.time_class
|
26
26
|
Class.new(self) do
|
27
27
|
def before(time)
|
28
|
-
return moment_before(time) if scalar.zero?
|
29
|
-
|
30
28
|
advanced_periods(:before, time).last.start_time
|
31
29
|
end
|
32
30
|
|
33
31
|
def after(time)
|
34
|
-
return moment_after(time) if scalar.zero?
|
35
|
-
|
36
32
|
advanced_periods(:after, time).last.end_time
|
37
33
|
end
|
38
34
|
|
@@ -52,31 +48,34 @@ module Biz
|
|
52
48
|
def self.day_class
|
53
49
|
Class.new(self) do
|
54
50
|
def before(time)
|
55
|
-
return moment_before(time) if scalar.zero?
|
56
|
-
|
57
51
|
periods(:before, time).first.end_time
|
58
52
|
end
|
59
53
|
|
60
54
|
def after(time)
|
61
|
-
return moment_after(time) if scalar.zero?
|
62
|
-
|
63
55
|
periods(:after, time).first.start_time
|
64
56
|
end
|
65
57
|
|
66
58
|
private
|
67
59
|
|
68
60
|
def periods(direction, time)
|
69
|
-
schedule
|
70
|
-
|
71
|
-
|
72
|
-
|
61
|
+
schedule
|
62
|
+
.periods
|
63
|
+
.public_send(
|
64
|
+
direction,
|
65
|
+
advanced_time(direction, schedule.in_zone.local(time))
|
66
|
+
)
|
73
67
|
end
|
74
68
|
|
75
69
|
def advanced_time(direction, time)
|
76
|
-
schedule
|
77
|
-
|
78
|
-
|
79
|
-
|
70
|
+
schedule
|
71
|
+
.in_zone
|
72
|
+
.on_date(
|
73
|
+
schedule
|
74
|
+
.dates
|
75
|
+
.days(scalar)
|
76
|
+
.public_send(direction, time.to_date),
|
77
|
+
DayTime.from_time(time)
|
78
|
+
)
|
80
79
|
end
|
81
80
|
end
|
82
81
|
end
|
@@ -100,14 +99,6 @@ module Biz
|
|
100
99
|
self.class.unit
|
101
100
|
end
|
102
101
|
|
103
|
-
def moment_before(time)
|
104
|
-
schedule.periods.before(time).first.end_time
|
105
|
-
end
|
106
|
-
|
107
|
-
def moment_after(time)
|
108
|
-
schedule.periods.after(time).first.start_time
|
109
|
-
end
|
110
|
-
|
111
102
|
[
|
112
103
|
*%i[second seconds minute minutes hour hours].map { |unit|
|
113
104
|
const_set(unit.to_s.capitalize, time_class)
|
data/lib/biz/day_time.rb
CHANGED
data/lib/biz/periods/abstract.rb
CHANGED
@@ -26,11 +26,10 @@ module Biz
|
|
26
26
|
def periods
|
27
27
|
Linear.new(week_periods, shifts, selector)
|
28
28
|
.lazy
|
29
|
-
.
|
30
|
-
.
|
29
|
+
.map { |period| period & boundary }
|
30
|
+
.reject(&:disjoint?)
|
31
31
|
.flat_map { |period| active_periods(period) }
|
32
32
|
.reject { |period| on_holiday?(period) }
|
33
|
-
.reject(&:empty?)
|
34
33
|
end
|
35
34
|
|
36
35
|
def week_periods
|
data/lib/biz/periods/after.rb
CHANGED
data/lib/biz/periods/before.rb
CHANGED
data/lib/biz/time_segment.rb
CHANGED
@@ -24,7 +24,7 @@ module Biz
|
|
24
24
|
:date
|
25
25
|
|
26
26
|
def duration
|
27
|
-
Duration.new(end_time - start_time)
|
27
|
+
Duration.new([end_time - start_time, 0].max)
|
28
28
|
end
|
29
29
|
|
30
30
|
def endpoints
|
@@ -32,7 +32,11 @@ module Biz
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def empty?
|
35
|
-
start_time
|
35
|
+
start_time == end_time
|
36
|
+
end
|
37
|
+
|
38
|
+
def disjoint?
|
39
|
+
start_time > end_time
|
36
40
|
end
|
37
41
|
|
38
42
|
def contains?(time)
|
@@ -40,17 +44,17 @@ module Biz
|
|
40
44
|
end
|
41
45
|
|
42
46
|
def &(other)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
self.class.new(
|
48
|
+
[self, other].map(&:start_time).max,
|
49
|
+
[self, other].map(&:end_time).min
|
50
|
+
)
|
47
51
|
end
|
48
52
|
|
49
53
|
def /(other)
|
50
54
|
[
|
51
55
|
self.class.new(start_time, other.start_time),
|
52
56
|
self.class.new(other.end_time, end_time)
|
53
|
-
].reject(&:
|
57
|
+
].reject(&:disjoint?).map { |potential| self & potential }
|
54
58
|
end
|
55
59
|
|
56
60
|
private
|
@@ -14,9 +14,9 @@ module Biz
|
|
14
14
|
periods
|
15
15
|
.map { |period| period & comparison_period(period, terminus) }
|
16
16
|
.each do |period|
|
17
|
-
yield period unless period.empty?
|
18
|
-
|
19
17
|
break if occurred?(period, terminus)
|
18
|
+
|
19
|
+
yield period unless period.disjoint?
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -26,13 +26,20 @@ module Biz
|
|
26
26
|
remaining = duration
|
27
27
|
|
28
28
|
periods
|
29
|
-
.map { |period| period & duration_period(period, remaining) }
|
30
29
|
.each do |period|
|
31
|
-
|
30
|
+
if overflow?(period, remaining)
|
31
|
+
remaining = Duration.new(0)
|
32
|
+
|
33
|
+
yield period
|
34
|
+
else
|
35
|
+
scoped_period = period & duration_period(period, remaining)
|
36
|
+
|
37
|
+
remaining -= scoped_period.duration
|
32
38
|
|
33
|
-
|
39
|
+
yield scoped_period unless scoped_period.disjoint?
|
34
40
|
|
35
|
-
|
41
|
+
break unless remaining.positive?
|
42
|
+
end
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
data/lib/biz/timeline/forward.rb
CHANGED
@@ -10,8 +10,12 @@ module Biz
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def occurred?(period,
|
14
|
-
period.
|
13
|
+
def occurred?(period, terminus)
|
14
|
+
period.start_time > terminus
|
15
|
+
end
|
16
|
+
|
17
|
+
def overflow?(period, remaining)
|
18
|
+
period.duration == remaining
|
15
19
|
end
|
16
20
|
|
17
21
|
def comparison_period(period, terminus)
|
data/lib/biz/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Little
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clavius
|