class Dynamoid::TypeCasting::DateTimeTypeCaster
Public Instance Methods
process(value)
click to toggle source
# 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
Private Instance Methods
seconds_to_offset(seconds)
click to toggle source
3600 -> “+01:00”
# File lib/dynamoid/type_casting.rb, line 251 def seconds_to_offset(seconds) ActiveSupport::TimeZone.seconds_to_utc_offset(seconds) end
string_utc_offset(string)
click to toggle source
# File lib/dynamoid/type_casting.rb, line 246 def string_utc_offset(string) Date._parse(string)[:offset] end