Class: Tomlrb::LocalTime

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tomlrb/local_time.rb

Instance Method Summary collapse

Constructor Details

#initialize(hour, min, sec) ⇒ LocalTime

Returns a new instance of LocalTime.



9
10
11
12
# File 'lib/tomlrb/local_time.rb', line 9

def initialize(hour, min, sec)
  @time = Time.new(0, 1, 1, hour, min, sec, '-00:00')
  @sec = sec
end

Instance Method Details

#==(other) ⇒ Object



29
30
31
32
# File 'lib/tomlrb/local_time.rb', line 29

def ==(other)
  other.kind_of?(self.class) &&
    @time == other.to_time(0, 1, 1)
end

#inspectObject



34
35
36
# File 'lib/tomlrb/local_time.rb', line 34

def inspect
  "#<#{self.class}: #{to_s}>"
end

#to_sObject



23
24
25
26
27
# File 'lib/tomlrb/local_time.rb', line 23

def to_s
  frac = (@sec - sec)
  frac_str = frac == 0 ? '' : "#{frac.to_s[1..-1]}"
  @time.strftime("%T") << frac_str
end

#to_time(year, month, day, offset = '-00:00') ⇒ Time

Returns the time of the date specified by params.

Parameters:

Returns:

  • (Time)

    the time of the date specified by params



19
20
21
# File 'lib/tomlrb/local_time.rb', line 19

def to_time(year, month, day, offset='-00:00')
  Time.new(year, month, day, hour, min, @sec, offset)
end