Skip to content

Commit

Permalink
Use _load/_dump to serialize when present
Browse files Browse the repository at this point in the history
  • Loading branch information
seejohnrun committed Dec 8, 2011
1 parent 96ac1bd commit 0124ae6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/ice_cube/time_util.rb
Expand Up @@ -23,14 +23,21 @@ def self.serialize_time(time)
if defined?(:ActiveSupport) && const_defined?(:ActiveSupport) && time.is_a?(ActiveSupport::TimeWithZone)
{ :time => time, :zone => time.time_zone.name }
elsif time.is_a?(Time)
time
if time.respond_to?(:_dump)
time._dump
else
time
end
end
end

# Deserialize a time serialized with serialize_time
def self.deserialize_time(time_or_hash)
return time_or_hash if time_or_hash.is_a?(Time) # for backward-compat
if time_or_hash.is_a?(Hash)
if time_or_hash.is_a?(Time)
time_or_hash
elsif time_or_hash.is_a?(String)
Time._load(time_or_hash)
elsif time_or_hash.is_a?(Hash)
time_or_hash[:time].in_time_zone(time_or_hash[:zone])
end
end
Expand Down

0 comments on commit 0124ae6

Please sign in to comment.