Skip to content

Commit f1eddea

Browse files
committed
✂️ 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.
1 parent 58d3e02 commit f1eddea

File tree

3 files changed

+15
-62
lines changed

3 files changed

+15
-62
lines changed

activesupport/CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
* Removed deprecated `Numeric#ago` and friends
2+
3+
Replacements:
4+
5+
5.ago => 5.seconds.ago
6+
5.until => 5.seconds.until
7+
5.since => 5.seconds.since
8+
5.from_now => 5.seconds.from_now
9+
10+
See #12389 for the history and rationale behind this.
11+
12+
*Godfrey Chan*
13+
114
* DateTime `advance` now supports partial days.
215

316
Before:

activesupport/lib/active_support/core_ext/numeric/time.rb

+1-19
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,7 @@ def fortnights
6161
end
6262
alias :fortnight :fortnights
6363

64-
# Reads best without arguments: 10.minutes.ago
65-
def ago(time = ::Time.current)
66-
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"
67-
time - self
68-
end
69-
70-
# Reads best with argument: 10.minutes.until(time)
71-
alias :until :ago
72-
73-
# Reads best with argument: 10.minutes.since(time)
74-
def since(time = ::Time.current)
75-
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"
76-
time + self
77-
end
78-
79-
# Reads best without arguments: 10.minutes.from_now
80-
alias :from_now :since
81-
82-
# Used with the standard time durations, like 1.hour.in_milliseconds --
64+
# Used with the standard time durations, like 1.hour.in_milliseconds --
8365
# so we can feed them to JavaScript functions like getTime().
8466
def in_milliseconds
8567
self * 1000

activesupport/test/core_ext/numeric_ext_test.rb

+1-43
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ def test_units
2222
end
2323
end
2424

25-
def test_deprecated_since_and_ago
26-
assert_equal @now + 1, assert_deprecated { 1.since(@now) }
27-
assert_equal @now - 1, assert_deprecated { 1.ago(@now) }
28-
end
29-
30-
def test_deprecated_since_and_ago_without_argument
31-
now = Time.now
32-
assert assert_deprecated { 1.since } >= now + 1
33-
now = Time.now
34-
assert assert_deprecated { 1.ago } >= now - 1
35-
end
36-
3725
def test_irregular_durations
3826
assert_equal @now.advance(:days => 3000), 3000.days.since(@now)
3927
assert_equal @now.advance(:months => 1), 1.month.since(@now)
@@ -84,36 +72,6 @@ def test_add_one_year_to_leap_day
8472
assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10) + 1.year
8573
end
8674

87-
def test_since_and_ago_anchored_to_time_now_when_time_zone_is_not_set
88-
Time.zone = nil
89-
with_env_tz 'US/Eastern' do
90-
Time.stubs(:now).returns Time.local(2000)
91-
# since
92-
assert_not_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.since }
93-
assert_equal Time.local(2000,1,1,0,0,5), assert_deprecated { 5.since }
94-
# ago
95-
assert_not_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.ago }
96-
assert_equal Time.local(1999,12,31,23,59,55), assert_deprecated { 5.ago }
97-
end
98-
end
99-
100-
def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_is_set
101-
Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
102-
with_env_tz 'US/Eastern' do
103-
Time.stubs(:now).returns Time.local(2000)
104-
# since
105-
assert_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.since }
106-
assert_equal Time.utc(2000,1,1,0,0,5), assert_deprecated { 5.since.time }
107-
assert_equal 'Eastern Time (US & Canada)', assert_deprecated { 5.since.time_zone.name }
108-
# ago
109-
assert_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.ago }
110-
assert_equal Time.utc(1999,12,31,23,59,55), assert_deprecated { 5.ago.time }
111-
assert_equal 'Eastern Time (US & Canada)', assert_deprecated { 5.ago.time_zone.name }
112-
end
113-
ensure
114-
Time.zone = nil
115-
end
116-
11775
protected
11876
def with_env_tz(new_tz = 'US/Eastern')
11977
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
@@ -435,7 +393,7 @@ def test_to_s__injected_on_proper_types
435393
assert_equal BigDecimal, BigDecimal("1000010").class
436394
assert_equal '1 Million', BigDecimal("1000010").to_s(:human)
437395
end
438-
396+
439397
def test_in_milliseconds
440398
assert_equal 10_000, 10.seconds.in_milliseconds
441399
end

0 commit comments

Comments
 (0)