Class: Tomlrb::LocalDateTime

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

Instance Method Summary collapse

Constructor Details

#initialize(year, month, day, hour, min, sec) ⇒ LocalDateTime

rubocop:disable Metrics/ParameterLists



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

def initialize(year, month, day, hour, min, sec) # rubocop:disable Metrics/ParameterLists
  @time = Time.new(year, month, day, hour, min, sec, '-00:00')
  @sec = sec
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
# File 'lib/tomlrb/local_date_time.rb', line 31

def ==(other)
  other.kind_of?(self.class) &&
    to_time == other.to_time
end

#inspectObject



36
37
38
# File 'lib/tomlrb/local_date_time.rb', line 36

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

#to_sObject



25
26
27
28
29
# File 'lib/tomlrb/local_date_time.rb', line 25

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

#to_time(offset = '-00:00') ⇒ Time

Parameters:

  • offset (String, Symbol, Numeric, nil) (defaults to: '-00:00')

    time zone offset.

    • when String, must be ‘+HH:MM’ format, ‘-HH:MM’ format, ‘UTC’, ‘A’..‘I’ or ‘K’..‘Z’. Arguments excluding ‘+-HH:MM’ are supporeted at Ruby >= 2.7.0

    • when Symbol, must be :dst(for summar time for local) or :std(for standard time).

    • when Numeric, it is time zone offset in second.

    • when nil, local time zone offset is used.

Returns:

  • (Time)


20
21
22
23
# File 'lib/tomlrb/local_date_time.rb', line 20

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