Permalink
Browse files

Fix marshal round-tripping of fractional seconds (Time#subsec).

  • Loading branch information...
jasoncodes committed Apr 17, 2011
1 parent b6843f2 commit 96546bb63bd5f1b24f5126e7a3314580bc59584f
@@ -37,6 +37,7 @@ def _load(marshaled_time)
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
@@ -808,4 +808,11 @@ def test_marshaling_with_frozen_local_instance
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

0 comments on commit 96546bb

Please sign in to comment.