提交 8ef3dfff 编写于 作者: G Geoff Buesing

TimeWithZone#- added, so that #- can handle a Time or TimeWithZone argument correctly

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8732 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 c95365a0
*SVN*
* TimeWithZone#- added, so that #- can handle a Time or TimeWithZone argument correctly [Geoff Buesing]
* with_timezone test helper renamed with_env_tz, to distinguish between setting ENV['TZ'] and setting Time.zone in tests [Geoff Buesing]
* Time#- coerces TimeWithZone argument to a Time instance so that difference in seconds can be calculated. Closes #10914 [Geoff Buesing, yyyc514]
......
......@@ -107,6 +107,12 @@ def <=>(other)
utc <=> other
end
# Need to override #- to intercept situation where a Time or Time With Zone object is passed in
# Otherwise, just pass on to method missing
def -(other)
other.acts_like?(:time) ? utc - other : method_missing(:-, other)
end
# A TimeProxy acts like a Time, so just return self
def to_time
self
......
......@@ -124,6 +124,7 @@ def test_minus_with_duration
def test_minus_with_time
assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['UTC'] ) - Time.utc(2000, 1, 1)
assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['Hawaii'] ) - Time.utc(2000, 1, 1)
end
def test_minus_with_time_with_zone
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册