Skip to content

Instantly share code, notes, and snippets.

@semarco
Forked from ayosec/utc-times.rb
Created July 11, 2012 13:50
Show Gist options
  • Save semarco/3090463 to your computer and use it in GitHub Desktop.
Save semarco/3090463 to your computer and use it in GitHub Desktop.
Force UTC times
class Hash
def times_with_utc
dup.tap do |new_hash|
each_key do |key|
value = self[key]
if ActiveSupport::TimeWithZone === value
new_hash[key] = value.utc
elsif Array === value || Hash === value
new_hash[key] = value.times_with_utc
end
end
end
end
end
class Array
def times_with_utc
map do |value|
if ActiveSupport::TimeWithZone === value
value.utc
else
value
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment