Skip to content

Commit

Permalink
Fix marshal round-tripping of fractional seconds (Time#subsec).
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncodes committed Apr 17, 2011
1 parent b6843f2 commit 96546bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions activesupport/lib/active_support/core_ext/time/marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/core_ext/time_ext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.