biz 1.2.0 → 1.2.1

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: 33c5eb58e4e8d9ee6f5b42c071c99e8c8cf8ed5b
4
- data.tar.gz: 05fdc0175b78e6147aaffcaea14d274955744a2d
3
+ metadata.gz: 1d05e74b61bbcd76562d54907d90b90252579da8
4
+ data.tar.gz: b30af6939b9302e91d00e10289da02ef4ea87bbf
5
5
  SHA512:
6
- metadata.gz: c6556e0069a7f41c67a0cdf9d80f7886b622b2cc043ba6c65a1bb6201d65f6a39facc1a8073b5c4d612f0d2d152a05b72bdbd8d2183dfc40d4cfc98ff34c4fc1
7
- data.tar.gz: b42dfdb7a0fbba2386b1fa13e45ced2314517ea8c35c9ec66873b5804c6ee7dea7b61f9c8ab03bbbf856428127a71e25ce9c9b7cc9eeb4718878536559e079c8
6
+ metadata.gz: ce1f8adb07629077dd1a6f9d9f9f297a993792de30d362960ea2b690cee778c6f320f1ffdcf75ad5196a0dbb0eaea086a3c5d4cc51926475b3aa8aa768c7db26
7
+ data.tar.gz: e78efec99aeb0175351750d4354930e061961287dacfd00c20b6a7fb49bd8c46d7651b337d31e2722e70e4d101a07b3059b26512451dfa6785ce5f3c48dea943
data/README.md CHANGED
@@ -131,6 +131,8 @@ require 'biz/core_ext'
131
131
 
132
132
  5.business_hours.after(Time.utc(2015, 4, 7, 8, 20))
133
133
 
134
+ 3.business_days.before(Time.utc(2015, 5, 9, 4, 12))
135
+
134
136
  Time.utc(2015, 8, 20, 9, 30).business_hours?
135
137
 
136
138
  Date.new(2015, 12, 10).business_day?
@@ -1,8 +1,12 @@
1
1
  module Biz
2
2
  class DayTime
3
3
 
4
- TIMESTAMP_FORMAT = '%02d:%02d'
5
- TIMESTAMP_PATTERN = /(?<hour>\d{2}):(?<minute>\d{2})/
4
+ module Timestamp
5
+
6
+ FORMAT = '%02d:%02d'
7
+ PATTERN = /\A(?<hour>\d{2}):(?<minute>\d{2})(:?(?<second>\d{2}))?\Z/
8
+
9
+ end
6
10
 
7
11
  include Comparable
8
12
 
@@ -11,16 +15,24 @@ module Biz
11
15
  class << self
12
16
 
13
17
  def from_time(time)
14
- new(time.hour * Time::MINUTES_IN_HOUR + time.min)
18
+ new(time.hour * Time::HOUR + time.min * Time::MINUTE + time.sec)
19
+ end
20
+
21
+ def from_minute(minute)
22
+ new(minute * Time::MINUTE)
15
23
  end
16
24
 
17
25
  def from_hour(hour)
18
- new(hour * Time::MINUTES_IN_HOUR)
26
+ new(hour * Time::HOUR)
19
27
  end
20
28
 
21
29
  def from_timestamp(timestamp)
22
- timestamp.match(TIMESTAMP_PATTERN) { |match|
23
- new(match[:hour].to_i * Time::MINUTES_IN_HOUR + match[:minute].to_i)
30
+ timestamp.match(Timestamp::PATTERN) { |match|
31
+ new(
32
+ match[:hour].to_i * Time::HOUR +
33
+ match[:minute].to_i * Time::MINUTE +
34
+ match[:second].to_i
35
+ )
24
36
  }
25
37
  end
26
38
 
@@ -42,29 +54,37 @@ module Biz
42
54
 
43
55
  end
44
56
 
45
- attr_reader :day_minute
57
+ attr_reader :day_second
46
58
 
47
59
  delegate strftime: :day_time
48
60
 
49
61
  delegate %i[
50
62
  to_i
51
63
  to_int
52
- ] => :day_minute
64
+ ] => :day_second
53
65
 
54
- def initialize(day_minute)
55
- @day_minute = Integer(day_minute)
66
+ def initialize(day_second)
67
+ @day_second = Integer(day_second)
56
68
  end
57
69
 
58
70
  def hour
59
- day_minute / Time::MINUTES_IN_HOUR
71
+ day_second / Time::HOUR
60
72
  end
61
73
 
62
74
  def minute
63
- day_minute % Time::MINUTES_IN_HOUR
75
+ day_second % Time::HOUR / Time::MINUTE
76
+ end
77
+
78
+ def second
79
+ day_second % Time::MINUTE
80
+ end
81
+
82
+ def day_minute
83
+ hour * Time::MINUTES_IN_HOUR + minute
64
84
  end
65
85
 
66
86
  def timestamp
67
- format(TIMESTAMP_FORMAT, hour, minute)
87
+ format(Timestamp::FORMAT, hour, minute)
68
88
  end
69
89
 
70
90
  def coerce(other)
@@ -76,7 +96,7 @@ module Biz
76
96
  def <=>(other)
77
97
  return nil unless other.respond_to?(:to_i)
78
98
 
79
- day_minute <=> other.to_i
99
+ day_second <=> other.to_i
80
100
  end
81
101
 
82
102
  private
@@ -87,7 +107,8 @@ module Biz
87
107
  Date::EPOCH.month,
88
108
  Date::EPOCH.mday,
89
109
  hour,
90
- minute
110
+ minute,
111
+ second
91
112
  )
92
113
  end
93
114
 
@@ -33,12 +33,13 @@ module Biz
33
33
  date.month,
34
34
  date.mday,
35
35
  day_time.hour,
36
- day_time.minute
36
+ day_time.minute,
37
+ day_time.second
37
38
  ),
38
39
  true
39
40
  )
40
41
  rescue TZInfo::PeriodNotFound
41
- on_date(date, DayTime.new(day_time.day_minute + MINUTES_IN_HOUR))
42
+ on_date(date, DayTime.new(day_time.day_second + HOUR))
42
43
  end
43
44
 
44
45
  def during_week(week, week_time)
@@ -1,5 +1,5 @@
1
1
  module Biz
2
2
 
3
- VERSION = '1.2.0'
3
+ VERSION = '1.2.1'
4
4
 
5
5
  end
@@ -35,6 +35,7 @@ module Biz
35
35
  delegate %i[
36
36
  hour
37
37
  minute
38
+ second
38
39
  day_minute
39
40
  timestamp
40
41
  ] => :day_time
@@ -9,7 +9,7 @@ module Biz
9
9
  end
10
10
 
11
11
  def day_time
12
- DayTime.new(day_of_week.day_minute(week_minute))
12
+ DayTime.from_minute(day_of_week.day_minute(week_minute))
13
13
  end
14
14
 
15
15
  memoize :day_of_week,
@@ -11,7 +11,7 @@ module Biz
11
11
  end
12
12
 
13
13
  def day_time
14
- DayTime.new(week_minute % Time::MINUTES_IN_DAY)
14
+ DayTime.from_minute(week_minute % Time::MINUTES_IN_DAY)
15
15
  end
16
16
 
17
17
  memoize :day_of_week,
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.2.0
4
+ version: 1.2.1
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: 2015-03-20 00:00:00.000000000 Z
12
+ date: 2015-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abstract_type