aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-07 04:39:50 -0700
committerJosé Valim <jose.valim@gmail.com>2011-05-07 04:39:50 -0700
commitf77cd7c7b6a4cf3dea15908c3f3e85c34b484aa9 (patch)
tree690709ab56e7bf41748836f3fd20c6bf6529f534 /activesupport
parentc444b0f67bf5f998f1f0e0271116fb111d1ba93a (diff)
parent96546bb63bd5f1b24f5126e7a3314580bc59584f (diff)
downloadrails-f77cd7c7b6a4cf3dea15908c3f3e85c34b484aa9.tar.gz
rails-f77cd7c7b6a4cf3dea15908c3f3e85c34b484aa9.tar.bz2
rails-f77cd7c7b6a4cf3dea15908c3f3e85c34b484aa9.zip
Merge pull request #286 from jasoncodes/marshal_subsec
Fix marshal round-tripping of fractional seconds (Time#subsec).
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/time/marshal.rb1
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb7
2 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/marshal.rb b/activesupport/lib/active_support/core_ext/time/marshal.rb
index 1a4d918ce7..457d3f5b62 100644
--- a/activesupport/lib/active_support/core_ext/time/marshal.rb
+++ b/activesupport/lib/active_support/core_ext/time/marshal.rb
@@ -37,6 +37,7 @@ if Time.local(2010).zone != Marshal.load(Marshal.dump(Time.local(2010))).zone
time.instance_eval do
if zone = defined?(@_zone) && remove_instance_variable('@_zone')
ary = to_a
+ ary[0] += subsec if ary[0] == sec
ary[-1] = zone
utc? ? Time.utc(*ary) : Time.local(*ary)
else
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 53d497013a..44e02109b1 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -808,4 +808,11 @@ class TimeExtMarshalingTest < Test::Unit::TestCase
assert_equal t.zone, unmarshaled.zone
assert_equal t, unmarshaled
end
+
+ def test_marshalling_preserves_fractional_seconds
+ t = Time.parse('00:00:00.500')
+ unmarshaled = Marshal.load(Marshal.dump(t))
+ assert_equal t.to_f, unmarshaled.to_f
+ assert_equal t, unmarshaled
+ end
end