Sha256: 824904222eb1aaf4ab82f44f038a3ba784e99d188928344895a716c1e67d3919
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
require 'time_duration/version' module TimeDuration def self.parse(args) Duration.parse(args) end class Duration include Comparable attr_accessor :second # TODO: format指定できるようにする def self.parse(time_as_string, format: '%H:%M') hour, minute = time_as_string.split(':').map(&:to_i) new(hour: hour, minute: minute) end def initialize(hour: 0, minute: 0, second: 0) hour = hour.to_i minute = minute.to_i second = second.to_i @second = hour * 3600 + minute * 60 + second end def hour minute / 60 + second / 3600 end def minute (second / 60) % 60 end # TODO: format指定できるようにする def to_s "%d:%02d" % [hour, minute] end def +(time_duration) self.class.new(second: second + time_duration.second) end def -(time_duration) self.class.new(second: second - time_duration.second) end def <=>(time_duration) self.second <=> time_duration.second end # override def inspect to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
time-duration-0.1.2 | lib/time_duration.rb |