hour 0.5.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hour.rb +7 -5
  3. data/lib/hour/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7d9267b3b089937946d971b89f0af4d5562a5ec
4
- data.tar.gz: 00d4d94e7769afcb2e127e9d539ccd19decd8bed
3
+ metadata.gz: d29d4aa32799ef7980b35d4d3b8290e5aaa610d5
4
+ data.tar.gz: fcbb928fa97720c3c84a6733abf02f7567e15886
5
5
  SHA512:
6
- metadata.gz: 98389becbcd5fc96e451d38907e18c5b29c99a235e76593d8ea39e7ddc07351f6917ff06f779f1a08402febeef3d0222290fda8c4a5e6913c1f57ccc8acf7cb9
7
- data.tar.gz: 668b7b56bdc3dbc1802c2d29213f729ffa44f5c67ea6217a39b148c51a371f59d48f7a1b0eab52c01dce7059aa7dd03e1d4774c460cc3803d728c2a2ca17e899
6
+ metadata.gz: 24a633548bb0c6f8b57037bddbca11ea016d58da2f5f6e8ea8c272943e41b4a69e3ee233c32a2f05de810a62dee8fa919f860fd22b6144664d5cbd81ab4a5ed0
7
+ data.tar.gz: 867d9de901f1395f8d0c132c1efb5d1429d8a55fe8db408f09dd1b30ba6f783d18adf0ed5a6d4c4c71bb8457acdf4628bd5a48596070a88dcf302e9d98196ec7
@@ -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] # Constrains assignment to the middle value, w/o the #Clamp method
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 '1' will be '01'
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, #day
24
- @hours_less_days, #hour
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
- 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".
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
@@ -1,3 +1,3 @@
1
1
  module Hour
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.3"
3
3
  end
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.1
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-18 00:00:00.000000000 Z
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler