Class: Dynamoid::TypeCasting::DateTimeTypeCaster

Inherits:
Base
  • Object
show all
Defined in:
lib/dynamoid/type_casting.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Dynamoid::TypeCasting::Base

Instance Method Details

#process(value) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/dynamoid/type_casting.rb', line 212

def process(value)
  if !value.respond_to?(:to_datetime)
    nil
  elsif value.is_a?(String)
    dt = DateTime.parse(value) rescue nil
    if dt
      seconds = string_utc_offset(value) || ApplicationTimeZone.utc_offset
      offset = seconds_to_offset(seconds)
      DateTime.new(dt.year, dt.mon, dt.mday, dt.hour, dt.min, dt.sec, offset)
    end
  else
    value.to_datetime
  end
end