Class: Aliyun::Log::Record::TypeCasting::DateTimeType
- Inherits:
-
Value
- Object
- Value
- Aliyun::Log::Record::TypeCasting::DateTimeType
show all
- Defined in:
- lib/aliyun/log/record/type_casting.rb
Instance Method Summary
collapse
Methods inherited from Value
#initialize
Instance Method Details
#cast(value) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/aliyun/log/record/type_casting.rb', line 77
def cast(value)
return nil unless value.respond_to?(:to_datetime)
dt = begin
::DateTime.parse(value)
rescue StandardError
nil
end
if dt
seconds = string_utc_offset(value) || 0
offset = seconds_to_offset(seconds)
::DateTime.new(dt.year, dt.mon, dt.mday, dt.hour, dt.min, dt.sec, offset)
else
value.to_datetime
end
end
|
#dump(value) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/aliyun/log/record/type_casting.rb', line 94
def dump(value)
if value.respond_to?(:to_datetime)
value.to_datetime.iso8601
else
value.to_s
end
end
|