class Hour

Defined in:

hour/version.cr
hour.cr

Constant Summary

PACKAGE = YAML.parse(RAW_PKG_DATA)

The whole content of shard.yml.

VERSION = PACKAGE["version"]

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.from(minutes = 0, seconds = 0) : self #

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)

[View source]
def self.new(h = 0, m = 0, s = 0) #

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.


[View source]
def self.now : self #

TODO Test me and document me.


[View source]

Class Method Detail

def self.from_time(time) #

TODO document and write tests.


[View source]
def self.parse(serialised_hour : String) #

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.


[View source]

Instance Method Detail

def +(other : Hour) : Hour #

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)

[View source]
def hours #

Returns a decorator providing convenience methods for working with hours.

Hour.new(1, 25).hours.round # => 1
Hour.new(1, 45).hours.round # => 2

[View source]
def minutes #

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

[View source]
def seconds #

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

[View source]
def to_s(format : String?) : String #

TODO Add formatting string support.

TODO Pad 0s. I. e. "#{self.hours}:#{format('%02d', self.minutes_over_the_hour)}"


[View source]
def to_time(today = Time.now) #

[View source]