11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/api_resource/typecasters/time_typecaster.rb', line 11
def self.from_api(value)
return value if value.is_a?(Time)
value = value.to_s
return nil if value.empty?
if value =~ ApiResource::Typecast::ISO_DATETIME
micro = ($7.to_f * 1_000_000).to_i
return self.new_time(false, $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, micro)
end
time_info = Date._parse(value)
time_info[:micro] = ((time_info[:sec_fraction].to_f % 1) * 1_000_000).to_i
if time_info[:zone].present? && time_info[:zone] =~ /^(\+|\-)[0-9]{1,2}:[0-9]{2}$/
new_time(true, *time_info.values_at(:year, :mon, :mday, :hour, :min, :sec, :zone))
else
new_time(false, *time_info.values_at(:year, :mon, :mday, :hour, :min, :sec, :micro))
end
end
|