Permalink
Browse files

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

  • Loading branch information...
1 parent 65a648b commit 1f6360621a9b584683764346f92cf1126d03d3ad @jasoncodes jasoncodes committed with tenderlove Apr 17, 2011
@@ -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
@@ -790,4 +790,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 1f63606

Please sign in to comment.