Browse files

Only call `in_time_zone` on Time or DateTime instances

Both String and Date now respond to in_time_zone so we need to
check if the value is a Time or a DateTime.
  • Loading branch information...
1 parent f0a9e2f commit 4dd563592208a1d1a5d617ceaa8c22aa8a56adb8 @pixeltrix pixeltrix committed Dec 11, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 activemodel/lib/active_model/serializers/xml.rb
View
7 activemodel/lib/active_model/serializers/xml.rb
@@ -2,6 +2,7 @@
require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/hash/conversions'
require 'active_support/core_ext/hash/slice'
+require 'active_support/core_ext/time/acts_like'
module ActiveModel
module Serializers
@@ -20,7 +21,11 @@ class Attribute #:nodoc:
def initialize(name, serializable, value)
@name, @serializable = name, serializable
- value = value.in_time_zone if value.respond_to?(:in_time_zone)
+
+ if value.acts_like?(:time) && value.respond_to?(:in_time_zone)
+ value = value.in_time_zone
+ end
+
@value = value
@type = compute_type
end

0 comments on commit 4dd5635

Please sign in to comment.