hour 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hour.rb +26 -17
- data/lib/hour/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: 91b0152711820c46e57ddb8107ab885c7921f19e
|
4
|
+
data.tar.gz: ae4d3d2efaf9a738e01df44f0695e1dddb88cef7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47c38b819df5ee82bd2bb2e4c76ac612fc908df7b4797cc82433c5f694dbd941771e101f28b8012816edddc008b000aacf165aaf5cb3016a991b8139a202c282
|
7
|
+
data.tar.gz: 02d1bd54e9590e794ddd16d751b541ee8740e31dda7d0f7f863ad55d5e1e67f141f6269530112abb3c0c71c05e1443313cae273cfd8044aeff143ce8aa9c2a78
|
data/lib/hour.rb
CHANGED
@@ -1,35 +1,44 @@
|
|
1
|
-
require "hour/version"
|
1
|
+
require "hour/version"
|
2
2
|
|
3
3
|
module Hour
|
4
4
|
class Hour
|
5
|
-
attr_reader :hours, :minutes, :to_seconds, :
|
5
|
+
attr_reader :hours, :minutes, :to_seconds, :days, :hours_less_days, :to_s, :to_formatted_s, :to_a, :to_time
|
6
6
|
|
7
7
|
def initialize(hours, minutes = 0)
|
8
|
-
hours, minutes = hours.split(':')
|
9
|
-
minutes = [0, minutes, 59].sort[1]
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@to_seconds = (
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@to_formatted_s = "#{@
|
16
|
-
"#{@
|
17
|
-
"#{minutes} minute#{'s' unless minutes == 1}"
|
8
|
+
hours, minutes = hours.split(':') if hours.is_a? String
|
9
|
+
@minutes = [0, minutes.to_i, 59].sort[1] # Constrains assignment to the middle value, w/o the #Clamp method
|
10
|
+
@to_a = [@hours = hours.to_i, @minutes]
|
11
|
+
@to_s = "#{'%02d' % @hours}:#{'%02d' % @minutes}" # Formats single-digits such that '1' will be '01'
|
12
|
+
@to_seconds = (@hours * 60 + @minutes) * 60
|
13
|
+
@days = @hours / 24 || 0
|
14
|
+
@hours_less_days = @hours - 24 * @days
|
15
|
+
@to_formatted_s = "#{@days} day#{'s' unless @days == 1}, " +
|
16
|
+
"#{@hours_less_days} hour#{'s' unless @hours_less_days == 1}, " +
|
17
|
+
"#{@minutes} minute#{'s' unless @minutes == 1}"
|
18
18
|
@to_time = Time.new(
|
19
19
|
0, #year
|
20
20
|
1, #month
|
21
|
-
1 + @
|
22
|
-
@
|
23
|
-
minutes,
|
21
|
+
1 + @days, #day
|
22
|
+
@hours_less_days, #hour
|
23
|
+
@minutes, #minute
|
24
24
|
0, #second
|
25
|
-
0 #UTC #TODO:
|
25
|
+
0 #UTC #TODO: handle both Time.zone format & deprecated UTC default?
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
29
|
+
def on_this_day(day_elect = Time.now)
|
30
|
+
day_elect.change(day: day_elect.day + @days,
|
31
|
+
hour: @hours_less_days,
|
32
|
+
min: @minutes)
|
33
|
+
end
|
34
|
+
|
29
35
|
def self.from_time(time_obj)
|
30
|
-
hour = time_obj.hour + (time_obj.day - 1) * 24 if time_obj.year == 0
|
36
|
+
hour = time_obj.hour + (time_obj.day - 1) * 24 if time_obj.year == 0 # Note that we expect Time input to be year 0, month 1 (minimum values). Incrementing day to a value above 1 means "add 24 * x hours", where x is the number of days above 1, so that a day value of 1 and hour value of 4 will be interpreted as "4 hours", whereas a day value of 2 and an hour value of 4 will be interpreted as "28 hours".
|
31
37
|
self.new(hour || time_obj.hour, time_obj.min)
|
32
38
|
end
|
33
39
|
|
40
|
+
alias_method :to_days, :days # DEPRECATION: to_days
|
41
|
+
alias_method :to_hours_less_days, :hours_less_days # DEPRECATION: to_hours_less_days
|
42
|
+
|
34
43
|
end
|
35
44
|
end
|
data/lib/hour/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- davegregg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|