Class: Tomlrb::LocalDateTime
- Inherits:
-
Object
- Object
- Tomlrb::LocalDateTime
- Extended by:
- Forwardable
- Defined in:
- lib/tomlrb/local_date_time.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(year, month, day, hour, min, sec) ⇒ LocalDateTime
constructor
rubocop:disable Metrics/ParameterLists.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #to_time(offset = '-00:00') ⇒ Time
Constructor Details
#initialize(year, month, day, hour, min, sec) ⇒ LocalDateTime
rubocop:disable Metrics/ParameterLists
11 12 13 14 15 16 |
# File 'lib/tomlrb/local_date_time.rb', line 11 def initialize(year, month, day, hour, min, sec) # rubocop:disable Metrics/ParameterLists @time = Time.utc(year, month, day, hour, min, sec) raise ArgumentError, "Invalid Local Date-Time: #{year}-#{month}-#{day}T#{hour}:#{min}:#{sec}" unless min.to_i == @time.min && hour.to_i == @time.hour && day.to_i == @time.day && month.to_i == @time.month && year.to_i == @time.year @sec = sec end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 38 |
# File 'lib/tomlrb/local_date_time.rb', line 35 def ==(other) other.is_a?(self.class) && to_time == other.to_time end |
#inspect ⇒ Object
40 41 42 |
# File 'lib/tomlrb/local_date_time.rb', line 40 def inspect "#<#{self.class}: #{self}>" end |
#to_s ⇒ Object
29 30 31 32 33 |
# File 'lib/tomlrb/local_date_time.rb', line 29 def to_s frac = (@sec - sec) frac_str = frac.zero? ? '' : frac.to_s[1..-1] @time.strftime('%FT%T') << frac_str end |
#to_time(offset = '-00:00') ⇒ Time
24 25 26 27 |
# File 'lib/tomlrb/local_date_time.rb', line 24 def to_time(offset = '-00:00') return @time if offset == '-00:00' Time.new(year, month, day, hour, min, @sec, offset) end |