Sha256: c120efd5feba5b1ee68365182d7f432b90cefe45dbeebb98cdb2292ef7ca2483
Contents?: true
Size: 884 Bytes
Versions: 3
Compression:
Stored size: 884 Bytes
Contents
require 'forwardable' module Tomlrb class LocalTime extend Forwardable def_delegators :@time, :hour, :min, :sec, :usec, :nsec def initialize(hour, min, sec) @time = Time.new(0, 1, 1, hour, min, sec, '-00:00') @sec = sec end # @param year [Integer] # @param month [Integer] # @param day [Integer] # @param offset see {LocalDateTime#to_time} # @return [Time] the time of the date specified by params def to_time(year, month, day, offset='-00:00') Time.new(year, month, day, hour, min, @sec, offset) end def to_s frac = (@sec - sec) frac_str = frac == 0 ? '' : "#{frac.to_s[1..-1]}" @time.strftime("%T") << frac_str end def ==(other) other.kind_of?(self.class) && @time == other.to_time(0, 1, 1) end def inspect "#<#{self.class}: #{to_s}>" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tomlrb-2.0.3 | lib/tomlrb/local_time.rb |
tomlrb-2.0.2 | lib/tomlrb/local_time.rb |
tomlrb-2.0.1 | lib/tomlrb/local_time.rb |