Class: Aws::Record::Marshalers::EpochTimeMarshaler

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-record/record/marshalers/epoch_time_marshaler.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ EpochTimeMarshaler

Returns a new instance of EpochTimeMarshaler



21
22
23
# File 'lib/aws-record/record/marshalers/epoch_time_marshaler.rb', line 21

def initialize(opts = {})
  @use_local_time = opts[:use_local_time] ? true : false
end

Instance Method Details

#serialize(raw_value) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aws-record/record/marshalers/epoch_time_marshaler.rb', line 34

def serialize(raw_value)
  time = type_cast(raw_value)
  if time.nil?
    nil
  elsif time.is_a?(::Time)
    time.to_i
  else
    msg = "expected a Time value or nil, got #{time.class}"
    raise ArgumentError, msg
  end
end

#type_cast(raw_value) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/aws-record/record/marshalers/epoch_time_marshaler.rb', line 25

def type_cast(raw_value)
  value = _format(raw_value)
  if !@use_local_time && value.is_a?(::Time)
    value.utc
  else
    value
  end
end