提交 48425351 编写于 作者: N Neer Friedman 提交者: Andrew White

Fix microsecond precision of Time#at_with_coercion

When Time.at_with_coercion (wraps Time.at) is called with a single
argument that "acts_like?(:time)" it is coerced to integer thus losing
it's microsecond percision.

This commits changes this to use `#to_f` to prevent the problem
上级 1a6eb1e5
...@@ -34,7 +34,7 @@ def current ...@@ -34,7 +34,7 @@ def current
# instances can be used when called with a single argument # instances can be used when called with a single argument
def at_with_coercion(*args) def at_with_coercion(*args)
if args.size == 1 && args.first.acts_like?(:time) if args.size == 1 && args.first.acts_like?(:time)
at_without_coercion(args.first.to_i) at_without_coercion(args.first.to_f)
else else
at_without_coercion(*args) at_without_coercion(*args)
end end
......
...@@ -711,6 +711,10 @@ def test_at_with_time_with_zone ...@@ -711,6 +711,10 @@ def test_at_with_time_with_zone
end end
end end
def test_at_with_time_microsecond_precision
assert_equal Time.at(Time.utc(2000, 1, 1, 0, 0, 0, 111)).to_f, Time.utc(2000, 1, 1, 0, 0, 0, 111).to_f
end
def test_eql? def test_eql?
assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) ) assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) )
assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Hawaii"]) ) assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Hawaii"]) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册