46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/presenter/types.rb', line 46
def self.typecast(value, options = {})
if value.is_a?(Time)
value
elsif value.is_a?(Hash)
Time.local(*value.values_at(:year, :month, :day, :hour, :minute, :second))
elsif value.is_a?(Date)
Time.local(value.year, value.month, value.day)
else
begin
dt = Date._strptime(value.to_s, options[:format] || "%a %b %d %H:%M:%S %Z %Y")
time = Time.local(dt[:year], dt[:mon], dt[:mday], dt[:hour], dt[:min], dt[:sec])
time += (time.utc_offset - dt[:offset]) if dt[:offset]
time
rescue StandardError => e
nil
end
end
end
|