biz 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/biz.rb +2 -1
- data/lib/biz/calculation/for_duration.rb +37 -26
- data/lib/biz/day_time.rb +1 -1
- data/lib/biz/schedule.rb +13 -11
- data/lib/biz/validation.rb +2 -2
- data/lib/biz/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27809869df3ee991371e2258e892863d22b5ad2e
|
4
|
+
data.tar.gz: 184a044cb47ccdb0437c5227da62bcbde65534aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f9fef46fd079453c482963e9e89b8ef9368451275f4626567b923119bf97c68af7cda4d44f73dcae27cf7f458aeabb980a9d6130dcd5c093beade3c32b48df4
|
7
|
+
data.tar.gz: f2f7dace5f2eb6b7baff6f6dc275afc7edb606e349ac7cddd7b32273ca3498434e137a1cb6b01ff3bc6d11a2b906baed602a81ac6eb003d1b2b3168b2da86c52
|
data/lib/biz.rb
CHANGED
@@ -11,11 +11,9 @@ module Biz
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.with_unit(schedule, scalar, unit)
|
14
|
-
unless UNITS.include?(unit)
|
15
|
-
fail ArgumentError, 'The unit is not supported.'
|
16
|
-
end
|
14
|
+
fail ArgumentError, 'unsupported unit' unless UNITS.include?(unit)
|
17
15
|
|
18
|
-
|
16
|
+
public_send(unit, schedule, scalar)
|
19
17
|
end
|
20
18
|
|
21
19
|
def self.unit
|
@@ -24,7 +22,9 @@ module Biz
|
|
24
22
|
|
25
23
|
def initialize(schedule, scalar)
|
26
24
|
@schedule = schedule
|
27
|
-
@scalar = scalar
|
25
|
+
@scalar = Integer(scalar)
|
26
|
+
|
27
|
+
fail ArgumentError, 'negative scalar' if @scalar < 0
|
28
28
|
end
|
29
29
|
|
30
30
|
protected
|
@@ -38,28 +38,40 @@ module Biz
|
|
38
38
|
self.class.unit
|
39
39
|
end
|
40
40
|
|
41
|
+
def moment_before(time)
|
42
|
+
schedule.periods.before(time).first.end_time
|
43
|
+
end
|
44
|
+
|
45
|
+
def moment_after(time)
|
46
|
+
schedule.periods.after(time).first.start_time
|
47
|
+
end
|
48
|
+
|
41
49
|
[
|
42
50
|
*%i[second seconds minute minutes hour hours].map { |unit|
|
43
51
|
const_set(
|
44
52
|
unit.to_s.capitalize,
|
45
53
|
Class.new(self) do
|
46
54
|
def before(time)
|
47
|
-
|
55
|
+
return moment_before(time) if scalar.zero?
|
56
|
+
|
57
|
+
advanced_periods(:before, time).last.start_time
|
48
58
|
end
|
49
59
|
|
50
60
|
def after(time)
|
51
|
-
|
61
|
+
return moment_after(time) if scalar.zero?
|
62
|
+
|
63
|
+
advanced_periods(:after, time).last.end_time
|
52
64
|
end
|
53
65
|
|
54
66
|
private
|
55
67
|
|
56
|
-
def
|
57
|
-
schedule
|
58
|
-
.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
68
|
+
def advanced_periods(direction, time)
|
69
|
+
schedule
|
70
|
+
.periods
|
71
|
+
.public_send(direction, time)
|
72
|
+
.timeline
|
73
|
+
.for(Duration.public_send(unit, scalar))
|
74
|
+
.to_a
|
63
75
|
end
|
64
76
|
end
|
65
77
|
)
|
@@ -69,33 +81,32 @@ module Biz
|
|
69
81
|
unit.to_s.capitalize,
|
70
82
|
Class.new(self) do
|
71
83
|
def before(time)
|
84
|
+
return moment_before(time) if scalar.zero?
|
85
|
+
|
72
86
|
periods(:before, time).first.end_time
|
73
87
|
end
|
74
88
|
|
75
89
|
def after(time)
|
90
|
+
return moment_after(time) if scalar.zero?
|
91
|
+
|
76
92
|
periods(:after, time).first.start_time
|
77
93
|
end
|
78
94
|
|
79
95
|
private
|
80
96
|
|
81
97
|
def periods(direction, time)
|
82
|
-
schedule.periods.
|
98
|
+
schedule.periods.public_send(
|
99
|
+
direction,
|
100
|
+
advanced_time(direction, schedule.in_zone.local(time))
|
101
|
+
)
|
83
102
|
end
|
84
103
|
|
85
|
-
def
|
104
|
+
def advanced_time(direction, time)
|
86
105
|
schedule.in_zone.on_date(
|
87
|
-
schedule.dates.days(scalar).
|
88
|
-
|
106
|
+
schedule.dates.days(scalar).public_send(direction, time),
|
107
|
+
DayTime.from_time(time)
|
89
108
|
)
|
90
109
|
end
|
91
|
-
|
92
|
-
def day_time(time)
|
93
|
-
DayTime.from_time(local(time))
|
94
|
-
end
|
95
|
-
|
96
|
-
def local(time)
|
97
|
-
schedule.in_zone.local(time)
|
98
|
-
end
|
99
110
|
end
|
100
111
|
)
|
101
112
|
}
|
data/lib/biz/day_time.rb
CHANGED
data/lib/biz/schedule.rb
CHANGED
@@ -48,17 +48,8 @@ module Biz
|
|
48
48
|
|
49
49
|
def &(other)
|
50
50
|
self.class.new do |config|
|
51
|
-
config.hours
|
52
|
-
|
53
|
-
other
|
54
|
-
.intervals
|
55
|
-
.map { |other_interval| interval & other_interval }
|
56
|
-
.reject(&:empty?)
|
57
|
-
}
|
58
|
-
)
|
59
|
-
|
60
|
-
config.holidays = [*holidays, *other.holidays].map(&:to_date)
|
61
|
-
|
51
|
+
config.hours = Interval.to_hours(intersected_intervals(other))
|
52
|
+
config.holidays = [*holidays, *other.holidays].map(&:to_date)
|
62
53
|
config.time_zone = time_zone.name
|
63
54
|
end
|
64
55
|
end
|
@@ -67,5 +58,16 @@ module Biz
|
|
67
58
|
|
68
59
|
attr_reader :configuration
|
69
60
|
|
61
|
+
private
|
62
|
+
|
63
|
+
def intersected_intervals(other)
|
64
|
+
intervals.flat_map { |interval|
|
65
|
+
other
|
66
|
+
.intervals
|
67
|
+
.map { |other_interval| interval & other_interval }
|
68
|
+
.reject(&:empty?)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
70
72
|
end
|
71
73
|
end
|
data/lib/biz/validation.rb
CHANGED
@@ -38,10 +38,10 @@ module Biz
|
|
38
38
|
end
|
39
39
|
|
40
40
|
RULES = [
|
41
|
-
Rule.new('
|
41
|
+
Rule.new('hours not hash-like') { |raw|
|
42
42
|
raw.hours.respond_to?(:to_h)
|
43
43
|
},
|
44
|
-
Rule.new('
|
44
|
+
Rule.new('hours not provided') { |raw|
|
45
45
|
raw.hours.to_h.any?
|
46
46
|
}
|
47
47
|
].freeze
|
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.5.
|
4
|
+
version: 1.5.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: 2016-
|
12
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clavius
|