Permalink
Browse files

Merge pull request #286 from jasoncodes/marshal_subsec

Fix marshal round-tripping of fractional seconds (Time#subsec).
  • Loading branch information...
2 parents c444b0f + 96546bb commit f77cd7c7b6a4cf3dea15908c3f3e85c34b484aa9 @josevalim josevalim committed May 7, 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
@@ -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 f77cd7c

Please sign in to comment.