Class: ISO8601Basic::Time

Inherits:
DateTime
  • Object
show all
Defined in:
lib/iso8601_basic/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/iso8601_basic/time.rb', line 3

def self.new(*args)
  case value = args[0]
  when Numeric
    super 2000, 1, 1, *args
  when String
    value = "T#{value}" unless value[0] == 'T'
    dt = ::DateTime.iso8601 "2000-01-01#{value}"
    super 2000, 1, 1, dt.hour, dt.minute, dt.second, dt.zone
  else super end
end

Instance Method Details

#+(other) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/iso8601_basic/time.rb', line 14

def +(other)
  case other
  when ISO8601Basic::Date
    ISO8601Basic::DateTime.new other.year, other.month, other.day,
      hour, minute, second, zone
  when ISO8601Basic::Duration
    seconds = [:hours, :minutes, :seconds].collect do |key|
      { seconds: 1, minutes: 60, hours: 3600 }[key] * other.to_h[key]
    end.inject :+
    super Rational(seconds.round, 86400)
  else super end
end

#inspectObject



31
32
33
# File 'lib/iso8601_basic/time.rb', line 31

def inspect
  "#<ISO8601Basic::Time: #{iso8601}>"
end

#iso8601Object



27
28
29
# File 'lib/iso8601_basic/time.rb', line 27

def iso8601
  super[10..-1]
end

#to_sObject



35
36
37
# File 'lib/iso8601_basic/time.rb', line 35

def to_s
  iso8601
end