class Dynamoid::Dumping::DateTimeDumper

datetime -> integer/string

Public Instance Methods

process(value) click to toggle source
# File lib/dynamoid/dumping.rb, line 212
def process(value)
  !value.nil? ? format_datetime(value, @options) : nil
end

Private Instance Methods

format_datetime(value, options) click to toggle source
# File lib/dynamoid/dumping.rb, line 218
def format_datetime(value, options)
  use_string_format = if options[:store_as_string].nil?
                        Dynamoid.config.store_datetime_as_string
                      else
                        options[:store_as_string]
                      end

  if use_string_format
    value_in_time_zone = Dynamoid::DynamodbTimeZone.in_time_zone(value)
    value_in_time_zone.iso8601
  else
    unless value.respond_to?(:to_i) && value.respond_to?(:nsec)
      value = value.to_time
    end
    BigDecimal(format('%d.%09d', value.to_i, value.nsec))
  end
end