class Hour
- Hour
- Reference
- Object
Defined in:
hour.crhour/version.cr
Constant Summary
-
PACKAGE =
YAML.parse(RAW_PKG_DATA)
-
The whole content of shard.yml.
-
VERSION =
PACKAGE["version"]
Constructors
-
.from(minutes = 0, seconds = 0) : self
Build an hour instance from either minutes or seconds.
-
.new(h : Int32 = 0, m : Int32 = 0, s : Int32 = 0)
Build an hour instance from h, m and s.
-
.now : self
TODO Test me and document me.
Class Method Summary
-
.from_time(time)
TODO document and write tests.
-
.parse(serialised_hour : String)
Build an hour instance from an hour string.
Instance Method Summary
-
#+(other : Hour) : Hour
Returns a new Hour instance returning the total time of the two hour instances.
-
#hours
Returns a decorator providing convenience methods for working with hours.
-
#minutes
Returns a decorator providing convenience methods for working with minutes.
-
#seconds
Returns a decorator providing convenience methods for working with seconds.
-
#to_s(format : String | Nil) : String
TODO Add formatting string support.
- #to_time(today = Time.now)
Constructor Detail
Build an hour instance from either minutes or seconds.
Unlike .new
, either of these values can be over 60.
Hour.from(minutes: 85) # => Hour.new(h: 1, m: 25)
Hour.from(seconds: 120) # => Hour.new(m: 2)
Build an hour instance from h, m and s. Raises an argument error if m or s is a value over 60.
For instantiating this class from a minutes or seconds value over 60, use .from
.
Class Method Detail
Build an hour instance from an hour string.
Hour.parse("1:00:00")
Hour.parse("1:00", "%h:%m?") # Will work with "1:00" or just "1".
TODO Implement me, test me and document me.
Instance Method Detail
Returns a new Hour instance returning the total time of the two hour instances.
Hour.new(m: 25, s: 10) + Hour.new(h: 1) # => Hour.new(1, 25, 10)
Returns a decorator providing convenience methods for working with hours.
Hour.new(1, 25).hours.round # => 1
Hour.new(1, 45).hours.round # => 2
Returns a decorator providing convenience methods for working with minutes.
Hour.new(1, 25, 52).minutes.value # => 25
Hour.new(1, 25, 52).minutes.round # => 26
Hour.new(1, 25, 52).minutes.total # => 85
Hour.new(1, 25, 52).minutes.round_total # => 86
Returns a decorator providing convenience methods for working with seconds.
Hour.new(m: 1, s: 10).seconds.value # => 10
Hour.new(1, 45, 10 ).seconds.total # => (1 * 60 * 60) + (45 * 60) + 10
TODO Add formatting string support.
TODO Pad 0s. I. e. "#{self.hours}:#{format('%02d', self.minutes_over_the_hour)}"