class ActiveAttr::Typecasting::DateTimeTypecaster

Typecasts an Object to a DateTime

@example Usage

typecaster = DateTimeTypecaster.new
typecaster.call("2012-01-01") #=> Sun, 01 Jan 2012 00:00:00 +0000

@since 0.5.0

Public Instance Methods

call(value) click to toggle source

Typecasts an object to a DateTime

Attempts to convert using to_datetime.

@example Typecast a String

typecaster.call("2012-01-01") #=> Sun, 01 Jan 2012 00:00:00 +0000

@param [Object, to_datetime] value The object to typecast

@return [DateTime, nil] The result of typecasting

@since 0.5.0

# File lib/active_attr/typecasting/date_time_typecaster.rb, line 26
def call(value)
  value.to_datetime if value.respond_to? :to_datetime
rescue ArgumentError
end