Class: Necromancer::DateTimeConverters::StringToDateTimeConverter

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

Overview

An object that converts a String to a DateTime

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 DateTime

Examples:

converer.call("1-1-2015")           # => "2015-01-01T00:00:00+00:00"
converer.call("1-1-2015 15:12:44")  # => "2015-01-01T15:12:44+00:00"


39
40
41
42
43
# File 'lib/necromancer/converters/date_time.rb', line 39

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