Class: Necromancer::DateTimeConverters::StringToTimeConverter

Inherits:
Converter
  • Object
show all
Defined in:
lib/necromancer/converters/date_time.rb

Instance Attribute Summary

Attributes inherited from Converter

#config, #convert, #source, #target

Instance Method Summary collapse

Methods inherited from Converter

create, #initialize, #raise_conversion_type

Constructor Details

This class inherits a constructor from Necromancer::Converter

Instance Method Details

#call(value, strict: config.strict) ⇒ Object

Convert a String value to a Time value

Examples:

converter.call("01-01-2015")       # => 2015-01-01 00:00:00 +0100
converter.call("01-01-2015 08:35") # => 2015-01-01 08:35:00 +0100
converter.call("12:35")            # => 2015-01-04 12:35:00 +0100

Parameters:

  • value (String)

    the value to convert



58
59
60
61
62
# File 'lib/necromancer/converters/date_time.rb', line 58

def call(value, strict: config.strict)
  Time.parse(value)
rescue StandardError
  strict ? raise_conversion_type(value) : value
end