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



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/dynamoid/type_casting.rb', line 225

def process(value)
  if !value.respond_to?(:to_datetime)
    nil
  elsif value.is_a?(String)
    dt = begin
           DateTime.parse(value)
         rescue StandardError
           nil
         end
    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