提交 f1eddea1 编写于 作者: G Godfrey Chan

removed deprecated `Numeric#ago` and friends

Replacements:

   5.ago   => 5.seconds.ago
   5.until => 5.seconds.until
   5.since => 5.seconds.since
   5.from_now => 5.seconds.from_now

The removed tests does not affect coverage – we have equivalent test cases in
the tests for `AS::Duration`.

See #12389 for the history and rationale behind this.
上级 58d3e025
* Removed deprecated `Numeric#ago` and friends
Replacements:
5.ago => 5.seconds.ago
5.until => 5.seconds.until
5.since => 5.seconds.since
5.from_now => 5.seconds.from_now
See #12389 for the history and rationale behind this.
*Godfrey Chan*
* DateTime `advance` now supports partial days.
Before:
......
......@@ -61,25 +61,7 @@ def fortnights
end
alias :fortnight :fortnights
# Reads best without arguments: 10.minutes.ago
def ago(time = ::Time.current)
ActiveSupport::Deprecation.warn "Calling #ago or #until on a number (e.g. 5.ago) is deprecated and will be removed in the future, use 5.seconds.ago instead"
time - self
end
# Reads best with argument: 10.minutes.until(time)
alias :until :ago
# Reads best with argument: 10.minutes.since(time)
def since(time = ::Time.current)
ActiveSupport::Deprecation.warn "Calling #since or #from_now on a number (e.g. 5.since) is deprecated and will be removed in the future, use 5.seconds.since instead"
time + self
end
# Reads best without arguments: 10.minutes.from_now
alias :from_now :since
# Used with the standard time durations, like 1.hour.in_milliseconds --
# Used with the standard time durations, like 1.hour.in_milliseconds --
# so we can feed them to JavaScript functions like getTime().
def in_milliseconds
self * 1000
......
......@@ -22,18 +22,6 @@ def test_units
end
end
def test_deprecated_since_and_ago
assert_equal @now + 1, assert_deprecated { 1.since(@now) }
assert_equal @now - 1, assert_deprecated { 1.ago(@now) }
end
def test_deprecated_since_and_ago_without_argument
now = Time.now
assert assert_deprecated { 1.since } >= now + 1
now = Time.now
assert assert_deprecated { 1.ago } >= now - 1
end
def test_irregular_durations
assert_equal @now.advance(:days => 3000), 3000.days.since(@now)
assert_equal @now.advance(:months => 1), 1.month.since(@now)
......@@ -84,36 +72,6 @@ def test_add_one_year_to_leap_day
assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10) + 1.year
end
def test_since_and_ago_anchored_to_time_now_when_time_zone_is_not_set
Time.zone = nil
with_env_tz 'US/Eastern' do
Time.stubs(:now).returns Time.local(2000)
# since
assert_not_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.since }
assert_equal Time.local(2000,1,1,0,0,5), assert_deprecated { 5.since }
# ago
assert_not_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.ago }
assert_equal Time.local(1999,12,31,23,59,55), assert_deprecated { 5.ago }
end
end
def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_is_set
Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
with_env_tz 'US/Eastern' do
Time.stubs(:now).returns Time.local(2000)
# since
assert_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.since }
assert_equal Time.utc(2000,1,1,0,0,5), assert_deprecated { 5.since.time }
assert_equal 'Eastern Time (US & Canada)', assert_deprecated { 5.since.time_zone.name }
# ago
assert_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.ago }
assert_equal Time.utc(1999,12,31,23,59,55), assert_deprecated { 5.ago.time }
assert_equal 'Eastern Time (US & Canada)', assert_deprecated { 5.ago.time_zone.name }
end
ensure
Time.zone = nil
end
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
......@@ -435,7 +393,7 @@ def test_to_s__injected_on_proper_types
assert_equal BigDecimal, BigDecimal("1000010").class
assert_equal '1 Million', BigDecimal("1000010").to_s(:human)
end
def test_in_milliseconds
assert_equal 10_000, 10.seconds.in_milliseconds
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册