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

#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 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"


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

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