Class: KDL::Types::Time

Inherits:
Value
  • Object
show all
Defined in:
lib/kdl/types/date_time.rb

Constant Summary collapse

REGEX =

TODO: this is not a perfect ISO8601 time string

/^T?((?:2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]+)?(?:Z|[+-]\d\d:\d\d)?)$/

Constants inherited from Value

Value::Null

Instance Attribute Summary

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Methods inherited from Value

#as_type, from, #initialize, #stringify_value, #to_s

Constructor Details

This class inherits a constructor from KDL::Value

Class Method Details

.call(value, type = 'time') ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
# File 'lib/kdl/types/date_time.rb', line 19

def self.call(value, type = 'time')
  return nil unless value.is_a? ::KDL::Value::String

  match = REGEX.match(value.value)
  raise ArgumentError, 'invalid time' if match.nil?

  time = ::Time.iso8601("#{::Date.today.iso8601}T#{match[1]}")
  new(time, type: type)
end