AWS services or capabilities described in AWS Documentation may vary by region/location. Click
Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
Class: Aws::Record::Marshalers::TimeMarshaler
- Inherits:
-
Object
- Object
- Aws::Record::Marshalers::TimeMarshaler
show all
- Defined in:
- lib/aws-record/record/marshalers/time_marshaler.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TimeMarshaler.
21
22
23
24
|
# File 'lib/aws-record/record/marshalers/time_marshaler.rb', line 21
def initialize(opts = {})
@formatter = opts[:formatter] || Iso8601Formatter
@use_local_time = opts[:use_local_time] ? true : false
end
|
Instance Method Details
#serialize(raw_value) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/aws-record/record/marshalers/time_marshaler.rb', line 35
def serialize(raw_value)
time = type_cast(raw_value)
if time.nil?
nil
elsif time.is_a?(::Time)
@formatter.format(time)
else
msg = "expected a Time value or nil, got #{time.class}"
raise ArgumentError, msg
end
end
|
#type_cast(raw_value) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/aws-record/record/marshalers/time_marshaler.rb', line 26
def type_cast(raw_value)
value = _format(raw_value)
if !@use_local_time && value.is_a?(::Time)
value.utc
else
value
end
end
|