biz 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/biz.rb +0 -3
- data/lib/biz/calculation/duration_within.rb +4 -1
- data/lib/biz/calculation/for_duration.rb +4 -7
- data/lib/biz/configuration.rb +16 -15
- data/lib/biz/day.rb +1 -1
- data/lib/biz/day_of_week.rb +4 -4
- data/lib/biz/day_time.rb +3 -3
- data/lib/biz/duration.rb +3 -4
- data/lib/biz/holiday.rb +1 -3
- data/lib/biz/interval.rb +0 -2
- data/lib/biz/periods/abstract.rb +9 -10
- data/lib/biz/schedule.rb +2 -2
- data/lib/biz/time_segment.rb +0 -2
- data/lib/biz/timeline/abstract.rb +13 -13
- data/lib/biz/validation.rb +10 -8
- data/lib/biz/version.rb +1 -1
- data/lib/biz/week.rb +1 -1
- data/lib/biz/week_time.rb +1 -1
- data/lib/biz/week_time/abstract.rb +0 -6
- data/lib/biz/week_time/end.rb +4 -5
- data/lib/biz/week_time/start.rb +6 -7
- metadata +3 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17b73c0b4db75f5474b6ea1ffb504295aa9d5b33
|
4
|
+
data.tar.gz: 760ad3e6cac89007667985a38e6d9cddd0587c3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7559524dfaf3702887f4250e7a899114fb52d94a28cb662b2680abc0ad94c073b2f6d20b719d00023eb54079f9418ca04e51ed502945c8ec2cebbbaccea91716
|
7
|
+
data.tar.gz: fc2f54dcd99a298ff208ea53978106424b1543615f9c30c82e85abe2759d4cbb9047f758c017df0ade11c4d303f00872ef682cd7298635ec6a8c37827ba3ad54
|
data/README.md
CHANGED
@@ -171,7 +171,7 @@ To open a console with the gem and sample schedule loaded:
|
|
171
171
|
|
172
172
|
## Copyright and license
|
173
173
|
|
174
|
-
Copyright 2015 Zendesk
|
174
|
+
Copyright 2015-16 Zendesk
|
175
175
|
|
176
176
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
177
177
|
this gem except in compliance with the License.
|
data/lib/biz.rb
CHANGED
@@ -4,7 +4,10 @@ module Biz
|
|
4
4
|
|
5
5
|
def initialize(schedule, calculation_period)
|
6
6
|
super(
|
7
|
-
schedule
|
7
|
+
schedule
|
8
|
+
.periods
|
9
|
+
.after(calculation_period.start_time)
|
10
|
+
.timeline
|
8
11
|
.until(calculation_period.end_time)
|
9
12
|
.map(&:duration)
|
10
13
|
.reduce(Duration.new(0), :+)
|
@@ -4,8 +4,6 @@ module Biz
|
|
4
4
|
|
5
5
|
UNITS = Set.new(%i[second seconds minute minutes hour hours day days])
|
6
6
|
|
7
|
-
include AbstractType
|
8
|
-
|
9
7
|
def self.with_unit(schedule, scalar, unit)
|
10
8
|
unless UNITS.include?(unit)
|
11
9
|
fail ArgumentError, 'The unit is not supported.'
|
@@ -23,9 +21,6 @@ module Biz
|
|
23
21
|
@scalar = scalar
|
24
22
|
end
|
25
23
|
|
26
|
-
abstract_method :before,
|
27
|
-
:after
|
28
|
-
|
29
24
|
protected
|
30
25
|
|
31
26
|
attr_reader :schedule,
|
@@ -39,7 +34,8 @@ module Biz
|
|
39
34
|
|
40
35
|
[
|
41
36
|
*%i[second seconds minute minutes hour hours].map { |unit|
|
42
|
-
const_set(
|
37
|
+
const_set(
|
38
|
+
unit.to_s.capitalize,
|
43
39
|
Class.new(self) do
|
44
40
|
def before(time)
|
45
41
|
timeline(:before, time).last.start_time
|
@@ -63,7 +59,8 @@ module Biz
|
|
63
59
|
)
|
64
60
|
},
|
65
61
|
*%i[day days].map { |unit|
|
66
|
-
const_set(
|
62
|
+
const_set(
|
63
|
+
unit.to_s.capitalize,
|
67
64
|
Class.new(self) do
|
68
65
|
def before(time)
|
69
66
|
periods(:before, time).first.end_time
|
data/lib/biz/configuration.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Biz
|
2
2
|
class Configuration
|
3
3
|
|
4
|
-
include Memoizable
|
5
|
-
|
6
4
|
def initialize
|
7
5
|
@raw = Raw.new.tap do |raw| yield raw if block_given? end
|
8
6
|
|
@@ -10,21 +8,27 @@ module Biz
|
|
10
8
|
end
|
11
9
|
|
12
10
|
def intervals
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
@intervals ||= begin
|
12
|
+
raw
|
13
|
+
.hours
|
14
|
+
.flat_map { |weekday, hours| weekday_intervals(weekday, hours) }
|
15
|
+
.sort_by(&:start_time)
|
16
|
+
.freeze
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
def holidays
|
19
|
-
|
21
|
+
@holidays ||= begin
|
22
|
+
raw.holidays.map { |date| Holiday.new(date, time_zone) }.freeze
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def time_zone
|
23
|
-
TZInfo::TimezoneProxy.new(raw.time_zone)
|
27
|
+
@time_zone ||= TZInfo::TimezoneProxy.new(raw.time_zone)
|
24
28
|
end
|
25
29
|
|
26
30
|
def weekdays
|
27
|
-
raw.hours.keys.to_set
|
31
|
+
@weekdays ||= raw.hours.keys.to_set.freeze
|
28
32
|
end
|
29
33
|
|
30
34
|
protected
|
@@ -49,10 +53,6 @@ module Biz
|
|
49
53
|
}
|
50
54
|
end
|
51
55
|
|
52
|
-
memoize :intervals,
|
53
|
-
:holidays,
|
54
|
-
:weekdays
|
55
|
-
|
56
56
|
Raw = Struct.new(:hours, :holidays, :time_zone) do
|
57
57
|
module Default
|
58
58
|
HOURS = {
|
@@ -61,9 +61,10 @@ module Biz
|
|
61
61
|
wed: {'09:00' => '17:00'},
|
62
62
|
thu: {'09:00' => '17:00'},
|
63
63
|
fri: {'09:00' => '17:00'}
|
64
|
-
}
|
65
|
-
|
66
|
-
|
64
|
+
}.freeze
|
65
|
+
|
66
|
+
HOLIDAYS = [].freeze
|
67
|
+
TIME_ZONE = 'Etc/UTC'.freeze
|
67
68
|
end
|
68
69
|
|
69
70
|
def initialize(*)
|
data/lib/biz/day.rb
CHANGED
data/lib/biz/day_of_week.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Biz
|
2
2
|
class DayOfWeek
|
3
3
|
|
4
|
-
SYMBOLS = [
|
4
|
+
SYMBOLS = %i[sun mon tue wed thu fri sat].freeze
|
5
5
|
|
6
6
|
def self.from_time(time)
|
7
7
|
DAYS.fetch(time.wday)
|
@@ -21,7 +21,7 @@ module Biz
|
|
21
21
|
|
22
22
|
class << self
|
23
23
|
|
24
|
-
|
24
|
+
alias from_date from_time
|
25
25
|
|
26
26
|
end
|
27
27
|
|
@@ -67,7 +67,7 @@ module Biz
|
|
67
67
|
THURSDAY = new(4),
|
68
68
|
FRIDAY = new(5),
|
69
69
|
SATURDAY = new(6)
|
70
|
-
]
|
70
|
+
].freeze
|
71
71
|
|
72
72
|
WEEKDAYS = [
|
73
73
|
MONDAY,
|
@@ -75,7 +75,7 @@ module Biz
|
|
75
75
|
WEDNESDAY,
|
76
76
|
THURSDAY,
|
77
77
|
FRIDAY
|
78
|
-
]
|
78
|
+
].freeze
|
79
79
|
|
80
80
|
end
|
81
81
|
end
|
data/lib/biz/day_time.rb
CHANGED
@@ -4,7 +4,7 @@ module Biz
|
|
4
4
|
VALID_SECONDS = 0..Time::SECONDS_IN_DAY
|
5
5
|
|
6
6
|
module Timestamp
|
7
|
-
FORMAT = '%02d:%02d'
|
7
|
+
FORMAT = '%02d:%02d'.freeze
|
8
8
|
PATTERN = /\A(?<hour>\d{2}):(?<minute>\d{2})(:?(?<second>\d{2}))?\Z/
|
9
9
|
end
|
10
10
|
|
@@ -44,13 +44,13 @@ module Biz
|
|
44
44
|
MIDNIGHT
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
alias am midnight
|
48
48
|
|
49
49
|
def noon
|
50
50
|
NOON
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
alias pm noon
|
54
54
|
|
55
55
|
def endnight
|
56
56
|
ENDNIGHT
|
data/lib/biz/duration.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Biz
|
2
2
|
class Duration
|
3
3
|
|
4
|
-
include Equalizer.new(:seconds)
|
5
4
|
include Comparable
|
6
5
|
|
7
6
|
extend Forwardable
|
@@ -12,19 +11,19 @@ module Biz
|
|
12
11
|
new(seconds)
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
alias second seconds
|
16
15
|
|
17
16
|
def minutes(minutes)
|
18
17
|
new(minutes * Time::SECONDS_IN_MINUTE)
|
19
18
|
end
|
20
19
|
|
21
|
-
|
20
|
+
alias minute minutes
|
22
21
|
|
23
22
|
def hours(hours)
|
24
23
|
new(hours * Time::SECONDS_IN_HOUR)
|
25
24
|
end
|
26
25
|
|
27
|
-
|
26
|
+
alias hour hours
|
28
27
|
|
29
28
|
end
|
30
29
|
|
data/lib/biz/holiday.rb
CHANGED
data/lib/biz/interval.rb
CHANGED
data/lib/biz/periods/abstract.rb
CHANGED
@@ -25,17 +25,16 @@ module Biz
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def periods
|
28
|
-
weeks
|
29
|
-
|
30
|
-
|
31
|
-
relevant?(business_period)
|
32
|
-
|
33
|
-
business_period
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
weeks
|
29
|
+
.lazy
|
30
|
+
.flat_map { |week| business_periods(week) }
|
31
|
+
.select { |business_period| relevant?(business_period) }
|
32
|
+
.map { |business_period| business_period & boundary }
|
33
|
+
.reject { |business_period|
|
34
|
+
schedule.holidays.any? { |holiday|
|
35
|
+
holiday.contains?(business_period.start_time)
|
36
|
+
}
|
37
37
|
}
|
38
|
-
}
|
39
38
|
end
|
40
39
|
|
41
40
|
def business_periods(week)
|
data/lib/biz/schedule.rb
CHANGED
@@ -22,7 +22,7 @@ module Biz
|
|
22
22
|
Dates.new(self)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
alias date dates
|
26
26
|
|
27
27
|
def time(scalar, unit)
|
28
28
|
Calculation::ForDuration.with_unit(self, scalar, unit)
|
@@ -40,7 +40,7 @@ module Biz
|
|
40
40
|
Calculation::OnHoliday.new(self, time).result
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
alias business_hours? in_hours?
|
44
44
|
|
45
45
|
def in_zone
|
46
46
|
Time.new(time_zone)
|
data/lib/biz/time_segment.rb
CHANGED
@@ -9,13 +9,13 @@ module Biz
|
|
9
9
|
def until(terminus)
|
10
10
|
return enum_for(:until, terminus) unless block_given?
|
11
11
|
|
12
|
-
periods
|
13
|
-
period & comparison_period(period, terminus)
|
14
|
-
|
15
|
-
|
12
|
+
periods
|
13
|
+
.map { |period| period & comparison_period(period, terminus) }
|
14
|
+
.each do |period|
|
15
|
+
yield period unless period.empty?
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
break if occurred?(period, terminus)
|
18
|
+
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def for(duration)
|
@@ -23,15 +23,15 @@ module Biz
|
|
23
23
|
|
24
24
|
remaining = duration
|
25
25
|
|
26
|
-
periods
|
27
|
-
period & duration_period(period, remaining)
|
28
|
-
|
29
|
-
|
26
|
+
periods
|
27
|
+
.map { |period| period & duration_period(period, remaining) }
|
28
|
+
.each do |period|
|
29
|
+
yield period unless period.empty?
|
30
30
|
|
31
|
-
|
31
|
+
remaining -= period.duration
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
break unless remaining.positive?
|
34
|
+
end
|
35
35
|
end
|
36
36
|
|
37
37
|
protected
|
data/lib/biz/validation.rb
CHANGED
@@ -37,14 +37,16 @@ module Biz
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
RULES = Set.new(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
RULES = Set.new(
|
41
|
+
[
|
42
|
+
Rule.new('Hours must be hash-like.') { |raw|
|
43
|
+
raw.hours.respond_to?(:to_h)
|
44
|
+
},
|
45
|
+
Rule.new('Hours must be provided.') { |raw|
|
46
|
+
raw.hours.to_h.any?
|
47
|
+
}
|
48
|
+
]
|
49
|
+
)
|
48
50
|
|
49
51
|
end
|
50
52
|
end
|
data/lib/biz/version.rb
CHANGED
data/lib/biz/week.rb
CHANGED
data/lib/biz/week_time.rb
CHANGED
@@ -2,9 +2,7 @@ module Biz
|
|
2
2
|
module WeekTime
|
3
3
|
class Abstract
|
4
4
|
|
5
|
-
include AbstractType
|
6
5
|
include Comparable
|
7
|
-
include Memoizable
|
8
6
|
|
9
7
|
extend Forwardable
|
10
8
|
|
@@ -49,8 +47,6 @@ module Biz
|
|
49
47
|
to_int
|
50
48
|
] => :week_minute
|
51
49
|
|
52
|
-
abstract_method :day_time
|
53
|
-
|
54
50
|
protected
|
55
51
|
|
56
52
|
def <=>(other)
|
@@ -71,8 +67,6 @@ module Biz
|
|
71
67
|
)
|
72
68
|
end
|
73
69
|
|
74
|
-
abstract_method :day_of_week
|
75
|
-
|
76
70
|
end
|
77
71
|
end
|
78
72
|
end
|
data/lib/biz/week_time/end.rb
CHANGED
@@ -3,18 +3,17 @@ module Biz
|
|
3
3
|
class End < Abstract
|
4
4
|
|
5
5
|
def day_time
|
6
|
-
DayTime.from_minute(day_of_week.day_minute(week_minute))
|
6
|
+
@day_time ||= DayTime.from_minute(day_of_week.day_minute(week_minute))
|
7
7
|
end
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def day_of_week
|
12
|
-
|
12
|
+
@day_of_week ||= begin
|
13
|
+
DayOfWeek::DAYS.find { |day| day.contains?(week_minute) }
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
|
-
memoize :day_of_week,
|
16
|
-
:day_time
|
17
|
-
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
data/lib/biz/week_time/start.rb
CHANGED
@@ -3,20 +3,19 @@ module Biz
|
|
3
3
|
class Start < Abstract
|
4
4
|
|
5
5
|
def day_time
|
6
|
-
DayTime.from_minute(week_minute % Time::MINUTES_IN_DAY)
|
6
|
+
@day_time ||= DayTime.from_minute(week_minute % Time::MINUTES_IN_DAY)
|
7
7
|
end
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def day_of_week
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
@day_of_week ||= begin
|
13
|
+
DayOfWeek::DAYS.fetch(
|
14
|
+
week_minute / Time::MINUTES_IN_DAY % Time::DAYS_IN_WEEK
|
15
|
+
)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
|
-
memoize :day_of_week,
|
18
|
-
:day_time
|
19
|
-
|
20
19
|
end
|
21
20
|
end
|
22
21
|
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.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Little
|
@@ -9,22 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: abstract_type
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 0.0.0
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 0.0.0
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: clavius
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,34 +25,6 @@ dependencies:
|
|
39
25
|
- - "~>"
|
40
26
|
- !ruby/object:Gem::Version
|
41
27
|
version: '1.0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: equalizer
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - "~>"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 0.0.0
|
49
|
-
type: :runtime
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 0.0.0
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: memoizable
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 0.4.0
|
63
|
-
type: :runtime
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 0.4.0
|
70
28
|
- !ruby/object:Gem::Dependency
|
71
29
|
name: tzinfo
|
72
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -183,3 +141,4 @@ signing_key:
|
|
183
141
|
specification_version: 4
|
184
142
|
summary: Business hours calculations
|
185
143
|
test_files: []
|
144
|
+
has_rdoc:
|