biz 1.3.4 → 1.4.0

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
  SHA1:
3
- metadata.gz: 17b73c0b4db75f5474b6ea1ffb504295aa9d5b33
4
- data.tar.gz: 760ad3e6cac89007667985a38e6d9cddd0587c3a
3
+ metadata.gz: 44d8fc924a2b8a852ff1764be148922e4008590d
4
+ data.tar.gz: 29ac9f7b0423c1b3d329b1d5e7485071fcf32ef3
5
5
  SHA512:
6
- metadata.gz: 7559524dfaf3702887f4250e7a899114fb52d94a28cb662b2680abc0ad94c073b2f6d20b719d00023eb54079f9418ca04e51ed502945c8ec2cebbbaccea91716
7
- data.tar.gz: fc2f54dcd99a298ff208ea53978106424b1543615f9c30c82e85abe2759d4cbb9047f758c017df0ade11c4d303f00872ef682cd7298635ec6a8c37827ba3ad54
6
+ metadata.gz: a4a37ee33bd1d466bc7fd6bab13a36ccc6c1fad2ecad17f4ea3332aec2fd5233fd7bd8419354966eba261eee22a74fc2c137458fd22cf2d9cda5ace0d909db8a
7
+ data.tar.gz: 54078121bab03914cbbeac6a03d2cc4c9dae945c8fbd36d387badf48bdafa5afbc7d3e40e76a818495cddc92b833144cb418905f836a4778655ea5559d6b93ed
@@ -2,7 +2,13 @@ module Biz
2
2
  module Calculation
3
3
  class ForDuration
4
4
 
5
- UNITS = Set.new(%i[second seconds minute minutes hour hours day days])
5
+ UNITS = %i[second seconds minute minutes hour hours day days].freeze
6
+
7
+ private_constant :UNITS
8
+
9
+ def self.units
10
+ UNITS
11
+ end
6
12
 
7
13
  def self.with_unit(schedule, scalar, unit)
8
14
  unless UNITS.include?(unit)
@@ -2,7 +2,9 @@ module Biz
2
2
  class Configuration
3
3
 
4
4
  def initialize
5
- @raw = Raw.new.tap do |raw| yield raw if block_given? end
5
+ @raw = Raw.new
6
+
7
+ yield raw if block_given?
6
8
 
7
9
  Validation.perform(raw)
8
10
  end
@@ -12,7 +14,7 @@ module Biz
12
14
  raw
13
15
  .hours
14
16
  .flat_map { |weekday, hours| weekday_intervals(weekday, hours) }
15
- .sort_by(&:start_time)
17
+ .sort
16
18
  .freeze
17
19
  end
18
20
  end
@@ -78,5 +80,8 @@ module Biz
78
80
  alias_method :business_hours=, :hours=
79
81
  end
80
82
 
83
+ private_constant :Raw,
84
+ :Default
85
+
81
86
  end
82
87
  end
@@ -1,7 +1,7 @@
1
1
  module Biz
2
2
  module CoreExt
3
3
  module Fixnum
4
- Calculation::ForDuration::UNITS.each do |unit|
4
+ Calculation::ForDuration.units.each do |unit|
5
5
  define_method("business_#{unit}") { Biz.time(self, unit) }
6
6
  end
7
7
  end
data/lib/biz/date.rb CHANGED
@@ -1,15 +1,20 @@
1
1
  module Biz
2
2
  class Date
3
3
 
4
- EPOCH = ::Date.new(2006, 1, 1)
4
+ EPOCH = ::Date.new(2006, 1, 1).freeze
5
+
6
+ private_constant :EPOCH
7
+
8
+ def self.epoch
9
+ EPOCH
10
+ end
5
11
 
6
12
  def self.from_day(day)
7
13
  EPOCH + day
8
14
  end
9
15
 
10
16
  def self.for_dst(date, day_time)
11
- date +
12
- (day_time.day_second + Time::SECONDS_IN_HOUR) / Time::SECONDS_IN_DAY
17
+ date + (day_time.day_second + Time.hour_seconds) / Time.day_seconds
13
18
  end
14
19
 
15
20
  end
data/lib/biz/dates.rb CHANGED
@@ -5,7 +5,7 @@ module Biz
5
5
  super(
6
6
  Clavius::Schedule.new do |c|
7
7
  c.weekdays = schedule.weekdays
8
- c.excluded = schedule.holidays.map(&:date)
8
+ c.excluded = schedule.holidays.map(&:to_date)
9
9
  end
10
10
  )
11
11
  end
@@ -3,44 +3,30 @@ module Biz
3
3
 
4
4
  SYMBOLS = %i[sun mon tue wed thu fri sat].freeze
5
5
 
6
- def self.from_time(time)
7
- DAYS.fetch(time.wday)
8
- end
9
-
10
- def self.from_symbol(symbol)
11
- DAYS.fetch(SYMBOLS.index(symbol))
12
- end
13
-
14
- def self.first
15
- DAYS.first
16
- end
6
+ include Comparable
17
7
 
18
- def self.last
19
- DAYS.last
8
+ def self.all
9
+ ALL
20
10
  end
21
11
 
22
- class << self
23
-
24
- alias from_date from_time
25
-
12
+ def self.from_symbol(symbol)
13
+ ALL.fetch(SYMBOLS.index(symbol))
26
14
  end
27
15
 
28
- attr_reader :wday
29
-
30
16
  def initialize(wday)
31
17
  @wday = Integer(wday)
32
18
  end
33
19
 
34
- def contains?(week_time)
35
- minutes.cover?(week_time)
20
+ def contains?(week_minute)
21
+ minutes.cover?(week_minute)
36
22
  end
37
23
 
38
24
  def start_minute
39
- wday * Time::MINUTES_IN_DAY
25
+ wday * Time.day_minutes
40
26
  end
41
27
 
42
28
  def end_minute
43
- start_minute + Time::MINUTES_IN_DAY
29
+ start_minute + Time.day_minutes
44
30
  end
45
31
 
46
32
  def minutes
@@ -52,30 +38,31 @@ module Biz
52
38
  end
53
39
 
54
40
  def day_minute(week_minute)
55
- (week_minute - 1) % Time::MINUTES_IN_DAY + 1
41
+ (week_minute - 1) % Time.day_minutes + 1
56
42
  end
57
43
 
58
44
  def symbol
59
45
  SYMBOLS.fetch(wday)
60
46
  end
61
47
 
62
- DAYS = [
63
- SUNDAY = new(0),
64
- MONDAY = new(1),
65
- TUESDAY = new(2),
66
- WEDNESDAY = new(3),
67
- THURSDAY = new(4),
68
- FRIDAY = new(5),
69
- SATURDAY = new(6)
70
- ].freeze
71
-
72
- WEEKDAYS = [
73
- MONDAY,
74
- TUESDAY,
75
- WEDNESDAY,
76
- THURSDAY,
77
- FRIDAY
78
- ].freeze
48
+ def wday?(other_wday)
49
+ wday == other_wday
50
+ end
51
+
52
+ def <=>(other)
53
+ return unless other.is_a?(self.class)
54
+
55
+ wday <=> other.wday
56
+ end
57
+
58
+ protected
59
+
60
+ attr_reader :wday
61
+
62
+ ALL = (0..6).map(&method(:new)).freeze
63
+
64
+ private_constant :SYMBOLS,
65
+ :ALL
79
66
 
80
67
  end
81
68
  end
data/lib/biz/day_time.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Biz
2
2
  class DayTime
3
3
 
4
- VALID_SECONDS = 0..Time::SECONDS_IN_DAY
4
+ VALID_SECONDS = (0..Time.day_seconds).freeze
5
5
 
6
6
  module Timestamp
7
7
  FORMAT = '%02d:%02d'.freeze
@@ -10,31 +10,29 @@ module Biz
10
10
 
11
11
  include Comparable
12
12
 
13
- extend Forwardable
14
-
15
13
  class << self
16
14
 
17
15
  def from_time(time)
18
16
  new(
19
- time.hour * Time::SECONDS_IN_HOUR +
20
- time.min * Time::SECONDS_IN_MINUTE +
17
+ time.hour * Time.hour_seconds +
18
+ time.min * Time.minute_seconds +
21
19
  time.sec
22
20
  )
23
21
  end
24
22
 
25
23
  def from_minute(minute)
26
- new(minute * Time::SECONDS_IN_MINUTE)
24
+ new(minute * Time.minute_seconds)
27
25
  end
28
26
 
29
27
  def from_hour(hour)
30
- new(hour * Time::SECONDS_IN_HOUR)
28
+ new(hour * Time.hour_seconds)
31
29
  end
32
30
 
33
31
  def from_timestamp(timestamp)
34
32
  timestamp.match(Timestamp::PATTERN) { |match|
35
33
  new(
36
- match[:hour].to_i * Time::SECONDS_IN_HOUR +
37
- match[:minute].to_i * Time::SECONDS_IN_MINUTE +
34
+ match[:hour].to_i * Time.hour_seconds +
35
+ match[:minute].to_i * Time.minute_seconds +
38
36
  match[:second].to_i
39
37
  )
40
38
  }
@@ -44,29 +42,12 @@ module Biz
44
42
  MIDNIGHT
45
43
  end
46
44
 
47
- alias am midnight
48
-
49
- def noon
50
- NOON
51
- end
52
-
53
- alias pm noon
54
-
55
45
  def endnight
56
46
  ENDNIGHT
57
47
  end
58
48
 
59
49
  end
60
50
 
61
- attr_reader :day_second
62
-
63
- delegate strftime: :format_time
64
-
65
- delegate %i[
66
- to_i
67
- to_int
68
- ] => :day_second
69
-
70
51
  def initialize(day_second)
71
52
  @day_second = Integer(day_second)
72
53
 
@@ -75,60 +56,45 @@ module Biz
75
56
  end
76
57
  end
77
58
 
59
+ attr_reader :day_second
60
+
78
61
  def hour
79
- day_second / Time::SECONDS_IN_HOUR
62
+ day_second / Time.hour_seconds
80
63
  end
81
64
 
82
65
  def minute
83
- day_second % Time::SECONDS_IN_HOUR / Time::SECONDS_IN_MINUTE
66
+ day_second % Time.hour_seconds / Time.minute_seconds
84
67
  end
85
68
 
86
69
  def second
87
- day_second % Time::SECONDS_IN_MINUTE
70
+ day_second % Time.minute_seconds
88
71
  end
89
72
 
90
73
  def day_minute
91
- hour * Time::MINUTES_IN_HOUR + minute
74
+ hour * Time.hour_minutes + minute
92
75
  end
93
76
 
94
77
  def for_dst
95
- self.class.new(
96
- (day_second + Time::SECONDS_IN_HOUR) % Time::SECONDS_IN_DAY
97
- )
78
+ self.class.new((day_second + Time.hour_seconds) % Time.day_seconds)
98
79
  end
99
80
 
100
81
  def timestamp
101
82
  format(Timestamp::FORMAT, hour, minute)
102
83
  end
103
84
 
104
- def coerce(other)
105
- [self.class.new(other), self]
106
- end
107
-
108
- protected
109
-
110
85
  def <=>(other)
111
- return nil unless other.respond_to?(:to_i)
112
-
113
- day_second <=> other.to_i
114
- end
86
+ return unless other.is_a?(self.class)
115
87
 
116
- private
117
-
118
- def format_time
119
- ::Time.new(
120
- Date::EPOCH.year,
121
- Date::EPOCH.month,
122
- Date::EPOCH.mday,
123
- hour,
124
- minute,
125
- second
126
- )
88
+ day_second <=> other.day_second
127
89
  end
128
90
 
129
91
  MIDNIGHT = from_hour(0)
130
- NOON = from_hour(12)
131
92
  ENDNIGHT = from_hour(24)
132
93
 
94
+ private_constant :VALID_SECONDS,
95
+ :Timestamp,
96
+ :MIDNIGHT,
97
+ :ENDNIGHT
98
+
133
99
  end
134
100
  end
data/lib/biz/duration.rb CHANGED
@@ -3,8 +3,6 @@ module Biz
3
3
 
4
4
  include Comparable
5
5
 
6
- extend Forwardable
7
-
8
6
  class << self
9
7
 
10
8
  def seconds(seconds)
@@ -14,23 +12,19 @@ module Biz
14
12
  alias second seconds
15
13
 
16
14
  def minutes(minutes)
17
- new(minutes * Time::SECONDS_IN_MINUTE)
15
+ new(minutes * Time.minute_seconds)
18
16
  end
19
17
 
20
18
  alias minute minutes
21
19
 
22
20
  def hours(hours)
23
- new(hours * Time::SECONDS_IN_HOUR)
21
+ new(hours * Time.hour_seconds)
24
22
  end
25
23
 
26
24
  alias hour hours
27
25
 
28
26
  end
29
27
 
30
- attr_reader :seconds
31
-
32
- delegate to_i: :seconds
33
-
34
28
  def initialize(seconds)
35
29
  @seconds = Integer(seconds)
36
30
  end
@@ -40,11 +34,11 @@ module Biz
40
34
  end
41
35
 
42
36
  def in_minutes
43
- seconds / Time::SECONDS_IN_MINUTE
37
+ seconds / Time.minute_seconds
44
38
  end
45
39
 
46
40
  def in_hours
47
- seconds / Time::SECONDS_IN_HOUR
41
+ seconds / Time.hour_seconds
48
42
  end
49
43
 
50
44
  def +(other)
@@ -63,17 +57,15 @@ module Biz
63
57
  self.class.new(seconds.abs)
64
58
  end
65
59
 
66
- def coerce(other)
67
- [self.class.new(other), self]
60
+ def <=>(other)
61
+ return unless other.is_a?(self.class)
62
+
63
+ seconds <=> other.seconds
68
64
  end
69
65
 
70
66
  protected
71
67
 
72
- def <=>(other)
73
- return nil unless other.respond_to?(:to_i)
74
-
75
- seconds <=> other.to_i
76
- end
68
+ attr_reader :seconds
77
69
 
78
70
  end
79
71
  end
data/lib/biz/holiday.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  module Biz
2
2
  class Holiday
3
3
 
4
- attr_reader :date,
5
- :time_zone
4
+ include Comparable
6
5
 
7
6
  def initialize(date, time_zone)
8
7
  @date = date
@@ -20,7 +19,22 @@ module Biz
20
19
  )
21
20
  end
22
21
 
23
- alias to_date date
22
+ def <=>(other)
23
+ return unless other.is_a?(self.class)
24
+
25
+ [date, time_zone] <=> [other.date, other.time_zone]
26
+ end
27
+
28
+ protected
29
+
30
+ attr_reader :date,
31
+ :time_zone
32
+
33
+ public
34
+
35
+ def to_date
36
+ date
37
+ end
24
38
 
25
39
  end
26
40
  end
data/lib/biz/interval.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  module Biz
2
2
  class Interval
3
3
 
4
- attr_reader :start_time,
5
- :end_time,
6
- :time_zone
4
+ include Comparable
7
5
 
8
6
  def initialize(start_time, end_time, time_zone)
9
7
  @start_time = start_time
@@ -29,5 +27,18 @@ module Biz
29
27
  )
30
28
  end
31
29
 
30
+ def <=>(other)
31
+ return unless other.is_a?(self.class)
32
+
33
+ [start_time, end_time, time_zone] <=>
34
+ [other.start_time, other.end_time, other.time_zone]
35
+ end
36
+
37
+ protected
38
+
39
+ attr_reader :start_time,
40
+ :end_time,
41
+ :time_zone
42
+
32
43
  end
33
44
  end
@@ -11,7 +11,7 @@ module Biz
11
11
  def weeks
12
12
  Range.new(
13
13
  Week.since_epoch(Time.new(time_zone).local(origin)),
14
- Week.since_epoch(Time::HEAT_DEATH)
14
+ Week.since_epoch(Time.heat_death)
15
15
  )
16
16
  end
17
17
 
@@ -9,9 +9,9 @@ module Biz
9
9
  private
10
10
 
11
11
  def weeks
12
- Week.since_epoch(Time.new(time_zone).local(origin)).downto(
13
- Week.since_epoch(Time::BIG_BANG)
14
- )
12
+ Week
13
+ .since_epoch(Time.new(time_zone).local(origin))
14
+ .downto(Week.since_epoch(Time.big_bang))
15
15
  end
16
16
 
17
17
  def relevant?(period)
data/lib/biz/time.rb CHANGED
@@ -1,22 +1,70 @@
1
1
  module Biz
2
2
  class Time
3
3
 
4
- SECONDS_IN_MINUTE = 60
5
- MINUTES_IN_HOUR = 60
6
- HOURS_IN_DAY = 24
7
- DAYS_IN_WEEK = 7
4
+ MINUTE_SECONDS = 60
5
+ HOUR_MINUTES = 60
6
+ DAY_HOURS = 24
7
+ WEEK_DAYS = 7
8
8
 
9
- SECONDS_IN_HOUR = SECONDS_IN_MINUTE * MINUTES_IN_HOUR
10
- SECONDS_IN_DAY = SECONDS_IN_HOUR * HOURS_IN_DAY
11
- SECONDS_IN_WEEK = SECONDS_IN_DAY * DAYS_IN_WEEK
9
+ HOUR_SECONDS = HOUR_MINUTES * MINUTE_SECONDS
10
+ DAY_SECONDS = DAY_HOURS * HOUR_SECONDS
12
11
 
13
- MINUTES_IN_DAY = MINUTES_IN_HOUR * HOURS_IN_DAY
14
- MINUTES_IN_WEEK = MINUTES_IN_DAY * DAYS_IN_WEEK
12
+ DAY_MINUTES = DAY_HOURS * HOUR_MINUTES
13
+ WEEK_MINUTES = WEEK_DAYS * DAY_MINUTES
15
14
 
16
- BIG_BANG = ::Time.new(-10**100)
17
- HEAT_DEATH = ::Time.new(10**100)
15
+ BIG_BANG = ::Time.new(-10**100).freeze
16
+ HEAT_DEATH = ::Time.new(10**100).freeze
18
17
 
19
- attr_reader :time_zone
18
+ private_constant :MINUTE_SECONDS,
19
+ :HOUR_MINUTES,
20
+ :DAY_HOURS,
21
+ :WEEK_DAYS,
22
+ :HOUR_SECONDS,
23
+ :DAY_SECONDS,
24
+ :DAY_MINUTES,
25
+ :WEEK_MINUTES,
26
+ :BIG_BANG,
27
+ :HEAT_DEATH
28
+
29
+ def self.minute_seconds
30
+ MINUTE_SECONDS
31
+ end
32
+
33
+ def self.hour_minutes
34
+ HOUR_MINUTES
35
+ end
36
+
37
+ def self.day_hours
38
+ DAY_HOURS
39
+ end
40
+
41
+ def self.week_days
42
+ WEEK_DAYS
43
+ end
44
+
45
+ def self.hour_seconds
46
+ HOUR_SECONDS
47
+ end
48
+
49
+ def self.day_seconds
50
+ DAY_SECONDS
51
+ end
52
+
53
+ def self.day_minutes
54
+ DAY_MINUTES
55
+ end
56
+
57
+ def self.week_minutes
58
+ WEEK_MINUTES
59
+ end
60
+
61
+ def self.big_bang
62
+ BIG_BANG
63
+ end
64
+
65
+ def self.heat_death
66
+ HEAT_DEATH
67
+ end
20
68
 
21
69
  def initialize(time_zone)
22
70
  @time_zone = time_zone
@@ -46,5 +94,9 @@ module Biz
46
94
  on_date(week.start_date + week_time.wday, week_time.day_time)
47
95
  end
48
96
 
97
+ protected
98
+
99
+ attr_reader :time_zone
100
+
49
101
  end
50
102
  end
@@ -1,22 +1,24 @@
1
1
  module Biz
2
2
  class TimeSegment
3
3
 
4
+ include Comparable
5
+
4
6
  def self.before(time)
5
- new(Time::BIG_BANG, time)
7
+ new(Time.big_bang, time)
6
8
  end
7
9
 
8
10
  def self.after(time)
9
- new(time, Time::HEAT_DEATH)
11
+ new(time, Time.heat_death)
10
12
  end
11
13
 
12
- attr_reader :start_time,
13
- :end_time
14
-
15
14
  def initialize(start_time, end_time)
16
15
  @start_time = start_time
17
16
  @end_time = end_time
18
17
  end
19
18
 
19
+ attr_reader :start_time,
20
+ :end_time
21
+
20
22
  def duration
21
23
  Duration.new(end_time - start_time)
22
24
  end
@@ -40,11 +42,10 @@ module Biz
40
42
  )
41
43
  end
42
44
 
43
- def /(other)
44
- [
45
- self.class.new(start_time, other.start_time),
46
- self.class.new(other.end_time, end_time)
47
- ].reject(&:empty?).map { |potential| self & potential }
45
+ def <=>(other)
46
+ return unless other.is_a?(self.class)
47
+
48
+ [start_time, end_time] <=> [other.start_time, other.end_time]
48
49
  end
49
50
 
50
51
  private
@@ -37,16 +37,16 @@ module Biz
37
37
 
38
38
  end
39
39
 
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
- )
40
+ RULES = [
41
+ Rule.new('Hours must be hash-like.') { |raw|
42
+ raw.hours.respond_to?(:to_h)
43
+ },
44
+ Rule.new('Hours must be provided.') { |raw|
45
+ raw.hours.to_h.any?
46
+ }
47
+ ].freeze
48
+
49
+ private_constant :RULES
50
50
 
51
51
  end
52
52
  end
data/lib/biz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Biz
2
- VERSION = '1.3.4'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
data/lib/biz/week.rb CHANGED
@@ -3,10 +3,8 @@ module Biz
3
3
 
4
4
  include Comparable
5
5
 
6
- extend Forwardable
7
-
8
6
  def self.from_date(date)
9
- new(Day.from_date(date).to_i / Time::DAYS_IN_WEEK)
7
+ new((date - Date.epoch).to_i / Time.week_days)
10
8
  end
11
9
 
12
10
  def self.from_time(time)
@@ -19,20 +17,12 @@ module Biz
19
17
 
20
18
  end
21
19
 
22
- attr_reader :week
23
-
24
- delegate %i[
25
- to_s
26
- to_i
27
- to_int
28
- ] => :week
29
-
30
20
  def initialize(week)
31
21
  @week = Integer(week)
32
22
  end
33
23
 
34
24
  def start_date
35
- Date.from_day(week * Time::DAYS_IN_WEEK)
25
+ Date.from_day(week * Time.week_days)
36
26
  end
37
27
 
38
28
  def succ
@@ -42,7 +32,7 @@ module Biz
42
32
  def downto(final_week)
43
33
  return enum_for(:downto, final_week) unless block_given?
44
34
 
45
- week.downto(final_week.to_i).each do |raw_week|
35
+ week.downto(final_week.week).each do |raw_week|
46
36
  yield self.class.new(raw_week)
47
37
  end
48
38
  end
@@ -51,17 +41,15 @@ module Biz
51
41
  self.class.new(week + other.week)
52
42
  end
53
43
 
54
- def coerce(other)
55
- [self.class.new(other), self]
44
+ def <=>(other)
45
+ return unless other.is_a?(self.class)
46
+
47
+ week <=> other.week
56
48
  end
57
49
 
58
50
  protected
59
51
 
60
- def <=>(other)
61
- return nil unless other.respond_to?(:to_i)
62
-
63
- week <=> other.to_i
64
- end
52
+ attr_reader :week
65
53
 
66
54
  end
67
55
  end
@@ -2,20 +2,18 @@ module Biz
2
2
  module WeekTime
3
3
  class Abstract
4
4
 
5
- include Comparable
6
-
7
5
  extend Forwardable
8
6
 
7
+ include Comparable
8
+
9
9
  def self.from_time(time)
10
10
  new(
11
- time.wday * Time::MINUTES_IN_DAY +
12
- time.hour * Time::MINUTES_IN_HOUR +
11
+ time.wday * Time.day_minutes +
12
+ time.hour * Time.hour_minutes +
13
13
  time.min
14
14
  )
15
15
  end
16
16
 
17
- attr_reader :week_minute
18
-
19
17
  def initialize(week_minute)
20
18
  @week_minute = Integer(week_minute)
21
19
  end
@@ -24,10 +22,6 @@ module Biz
24
22
  day_of_week.symbol
25
23
  end
26
24
 
27
- def coerce(other)
28
- [self.class.new(other), self]
29
- end
30
-
31
25
  delegate wday: :day_of_week
32
26
 
33
27
  delegate %i[
@@ -39,33 +33,15 @@ module Biz
39
33
  timestamp
40
34
  ] => :day_time
41
35
 
42
- delegate strftime: :week_time
43
-
44
- delegate %i[
45
- to_s
46
- to_i
47
- to_int
48
- ] => :week_minute
49
-
50
- protected
51
-
52
36
  def <=>(other)
53
- return nil unless other.respond_to?(:to_i)
37
+ return unless other.is_a?(WeekTime::Abstract)
54
38
 
55
- week_minute <=> other.to_i
39
+ week_minute <=> other.week_minute
56
40
  end
57
41
 
58
- private
42
+ protected
59
43
 
60
- def week_time
61
- ::Time.new(
62
- Date::EPOCH.year,
63
- Date::EPOCH.month,
64
- Date::EPOCH.mday + wday,
65
- hour,
66
- minute
67
- )
68
- end
44
+ attr_reader :week_minute
69
45
 
70
46
  end
71
47
  end
@@ -9,9 +9,7 @@ module Biz
9
9
  private
10
10
 
11
11
  def day_of_week
12
- @day_of_week ||= begin
13
- DayOfWeek::DAYS.find { |day| day.contains?(week_minute) }
14
- end
12
+ @day_of_week ||= DayOfWeek.all.find { |day| day.contains?(week_minute) }
15
13
  end
16
14
 
17
15
  end
@@ -3,16 +3,16 @@ module Biz
3
3
  class Start < Abstract
4
4
 
5
5
  def day_time
6
- @day_time ||= DayTime.from_minute(week_minute % Time::MINUTES_IN_DAY)
6
+ @day_time ||= DayTime.from_minute(week_minute % Time.day_minutes)
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.fetch(
14
- week_minute / Time::MINUTES_IN_DAY % Time::DAYS_IN_WEEK
15
- )
13
+ DayOfWeek.all.find { |day_of_week|
14
+ day_of_week.wday?(week_minute / Time.day_minutes % Time.week_days)
15
+ }
16
16
  end
17
17
  end
18
18
 
data/lib/biz.rb CHANGED
@@ -44,7 +44,6 @@ require 'biz/time'
44
44
  require 'biz/calculation'
45
45
  require 'biz/configuration'
46
46
  require 'biz/dates'
47
- require 'biz/day'
48
47
  require 'biz/day_of_week'
49
48
  require 'biz/day_time'
50
49
  require 'biz/duration'
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
4
+ version: 1.4.0
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-02-13 00:00:00.000000000 Z
12
+ date: 2016-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clavius
@@ -89,7 +89,6 @@ files:
89
89
  - lib/biz/core_ext/time.rb
90
90
  - lib/biz/date.rb
91
91
  - lib/biz/dates.rb
92
- - lib/biz/day.rb
93
92
  - lib/biz/day_of_week.rb
94
93
  - lib/biz/day_time.rb
95
94
  - lib/biz/duration.rb
@@ -136,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
135
  version: '0'
137
136
  requirements: []
138
137
  rubyforge_project:
139
- rubygems_version: 2.4.5.1
138
+ rubygems_version: 2.5.1
140
139
  signing_key:
141
140
  specification_version: 4
142
141
  summary: Business hours calculations
143
142
  test_files: []
144
- has_rdoc:
data/lib/biz/day.rb DELETED
@@ -1,51 +0,0 @@
1
- module Biz
2
- class Day
3
-
4
- include Comparable
5
-
6
- extend Forwardable
7
-
8
- def self.from_date(date)
9
- new((date - Date::EPOCH).to_i)
10
- end
11
-
12
- def self.from_time(time)
13
- from_date(time.to_date)
14
- end
15
-
16
- class << self
17
-
18
- alias since_epoch from_time
19
-
20
- end
21
-
22
- attr_reader :day
23
-
24
- delegate %i[
25
- to_s
26
- to_i
27
- to_int
28
- ] => :day
29
-
30
- def initialize(day)
31
- @day = Integer(day)
32
- end
33
-
34
- def to_date
35
- Date.from_day(day)
36
- end
37
-
38
- def coerce(other)
39
- [self.class.new(other), self]
40
- end
41
-
42
- protected
43
-
44
- def <=>(other)
45
- return nil unless other.respond_to?(:to_i)
46
-
47
- day <=> other.to_i
48
- end
49
-
50
- end
51
- end