hour 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hour.rb +7 -5
- 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: d29d4aa32799ef7980b35d4d3b8290e5aaa610d5
|
4
|
+
data.tar.gz: fcbb928fa97720c3c84a6733abf02f7567e15886
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24a633548bb0c6f8b57037bddbca11ea016d58da2f5f6e8ea8c272943e41b4a69e3ee233c32a2f05de810a62dee8fa919f860fd22b6144664d5cbd81ab4a5ed0
|
7
|
+
data.tar.gz: 867d9de901f1395f8d0c132c1efb5d1429d8a55fe8db408f09dd1b30ba6f783d18adf0ed5a6d4c4c71bb8457acdf4628bd5a48596070a88dcf302e9d98196ec7
|
data/lib/hour.rb
CHANGED
@@ -6,11 +6,11 @@ module Hour
|
|
6
6
|
|
7
7
|
def initialize(hours, minutes = 0)
|
8
8
|
hours, minutes = hours.split(':') if hours.is_a? String
|
9
|
-
@minutes = [0, minutes.to_i, 59].sort[1]
|
9
|
+
@minutes = [minimum = 0, minutes.to_i, maximum = 59].sort[1]
|
10
10
|
@minutes_in_base10 = @minutes.to_f / 60
|
11
11
|
@to_a = [@hours = hours.to_i, @minutes]
|
12
12
|
@to_base10 = @hours + @minutes_in_base10
|
13
|
-
@to_s = "#{'%02d' % @hours}:#{'%02d' % @minutes}" # Formats single-digits such that
|
13
|
+
@to_s = "#{'%02d' % @hours}:#{'%02d' % @minutes}" # Formats single-digits such that 1 will read '01'
|
14
14
|
@to_seconds = (@hours * 60 + @minutes) * 60
|
15
15
|
@days = @hours / 24 || 0
|
16
16
|
@hours_less_days = @hours - 24 * @days
|
@@ -20,8 +20,8 @@ module Hour
|
|
20
20
|
@to_time = Time.new(
|
21
21
|
0, #year
|
22
22
|
1, #month
|
23
|
-
1 + @days,
|
24
|
-
@hours_less_days,
|
23
|
+
1 + @days, #day
|
24
|
+
@hours_less_days, #hour
|
25
25
|
@minutes, #minute
|
26
26
|
0, #second
|
27
27
|
0 #UTC #TODO: handle both Time.zone format & deprecated UTC default?
|
@@ -35,11 +35,13 @@ module Hour
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.from_time(time_obj)
|
38
|
-
|
38
|
+
return nil if time_obj.nil?
|
39
|
+
hour = time_obj.hour + (time_obj.day - 1) * 24 if time_obj.year.zero? # 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."
|
39
40
|
self.new(hour || time_obj.hour, time_obj.min)
|
40
41
|
end
|
41
42
|
|
42
43
|
def self.from_base10(num)
|
44
|
+
return nil if num.nil?
|
43
45
|
hour, minute = num.divmod(1)
|
44
46
|
self.new(hour, minute * 60)
|
45
47
|
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.5.
|
4
|
+
version: 0.5.3
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|