biz 1.8.1 → 1.8.2

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: 3467afd950542680b2be1e34d7810a643f482e993bde21c63f972612885138d5
4
- data.tar.gz: 195dc3df994b9a964b5682d6ed6b5174ce78b803ffa6a45a44034d33c0fc7f17
3
+ metadata.gz: 78100d6bedcc407d7fd7f9d740963d7484e4bc2e211bb4f3d3b2ed8d30e2e85d
4
+ data.tar.gz: e2a72d2cf20cc430aab2db269d48e025c208da15b54d55afb2c00b08380fb925
5
5
  SHA512:
6
- metadata.gz: 64f7b5fbedb898d6237edb853d80656cd7d511aa8bc91593fc8e2c181726a83675f3e2276231d92198118b9ab9189520f13981dda05192dc2bc1c155a6d79fde
7
- data.tar.gz: eb583811538b0f27a5b78ba65db35c2c724110c7de99fa005f1593f1c5f654a9fdf1ce18b8addd062ffcc795a01f2b632307ba94588f763c283380dd36c7f0d5
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-18 Zendesk
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.periods.public_send(
70
- direction,
71
- advanced_time(direction, schedule.in_zone.local(time))
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.in_zone.on_date(
77
- schedule.dates.days(scalar).public_send(direction, time),
78
- DayTime.from_time(time)
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)
@@ -7,7 +7,8 @@ module Biz
7
7
 
8
8
  module Timestamp
9
9
  FORMAT = '%02d:%02d'
10
- PATTERN = /\A(?<hour>\d{2}):(?<minute>\d{2})(:?(?<second>\d{2}))?\Z/
10
+ PATTERN =
11
+ /\A(?<hour>\d{2}):(?<minute>\d{2})(:?(?<second>\d{2}))?\Z/.freeze
11
12
  end
12
13
 
13
14
  include Comparable
@@ -26,11 +26,10 @@ module Biz
26
26
  def periods
27
27
  Linear.new(week_periods, shifts, selector)
28
28
  .lazy
29
- .select { |period| relevant?(period) }
30
- .map { |period| period & boundary }
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
@@ -29,10 +29,6 @@ module Biz
29
29
  )
30
30
  end
31
31
 
32
- def relevant?(period)
33
- origin < period.end_time
34
- end
35
-
36
32
  end
37
33
  end
38
34
  end
@@ -28,10 +28,6 @@ module Biz
28
28
  .downto(Week.since_epoch(Time.big_bang))
29
29
  end
30
30
 
31
- def relevant?(period)
32
- origin > period.start_time
33
- end
34
-
35
31
  def active_periods(*)
36
32
  super.reverse
37
33
  end
@@ -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 >= end_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
- lower_bound = [self, other].map(&:start_time).max
44
- upper_bound = [self, other].map(&:end_time).min
45
-
46
- self.class.new(lower_bound, [lower_bound, upper_bound].max)
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(&:empty?).map { |potential| self & potential }
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
- yield period unless period.empty?
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
- remaining -= period.duration
39
+ yield scoped_period unless scoped_period.disjoint?
34
40
 
35
- break unless remaining.positive?
41
+ break unless remaining.positive?
42
+ end
36
43
  end
37
44
  end
38
45
 
@@ -10,8 +10,12 @@ module Biz
10
10
 
11
11
  private
12
12
 
13
- def occurred?(period, time)
14
- period.start_time <= time
13
+ def occurred?(period, terminus)
14
+ period.end_time <= terminus
15
+ end
16
+
17
+ def overflow?(*)
18
+ false
15
19
  end
16
20
 
17
21
  def comparison_period(period, terminus)
@@ -10,8 +10,12 @@ module Biz
10
10
 
11
11
  private
12
12
 
13
- def occurred?(period, time)
14
- period.end_time >= time
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Biz
4
- VERSION = '1.8.1'
4
+ VERSION = '1.8.2'
5
5
  end
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.1
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: 2018-10-30 00:00:00.000000000 Z
12
+ date: 2019-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clavius