Class: Necromancer::DateTimeConverters::StringToTimeConverter

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

Instance Attribute Summary

Attributes inherited from Converter

#convert, #source, #target

Instance Method Summary collapse

Methods inherited from Converter

create, #fail_conversion_type, #initialize

Constructor Details

This class inherits a constructor from Necromancer::Converter

Instance Method Details

#call(value, options = {}) ⇒ 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



60
61
62
63
64
65
# File 'lib/necromancer/converters/date_time.rb', line 60

def call(value, options = {})
  strict = options.fetch(:strict, config.strict)
  Time.parse(value)
rescue
  strict ? fail_conversion_type(value) : value
end