aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/numeric/time.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2013-09-27 12:51:36 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2013-11-26 22:24:19 -0800
commit1f1613604925823be4b15893fbb8f957a38dd0b8 (patch)
treee80aee6332bcd19c5f969151e9f667b919558d5b /activesupport/lib/active_support/core_ext/numeric/time.rb
parent5fdbec7dd15a8e6edef861899accb8b3b69cc87a (diff)
downloadrails-1f1613604925823be4b15893fbb8f957a38dd0b8.tar.gz
rails-1f1613604925823be4b15893fbb8f957a38dd0b8.tar.bz2
rails-1f1613604925823be4b15893fbb8f957a38dd0b8.zip
Deprecated Numeric#{ago,until,since,from_now}
The user is expected to explicitly convert the value into an AS::Duration, i.e. `5.ago` => `5.seconds.ago` This will help to catch subtle bugs like: def recent?(days = 3) self.created_at >= days.ago end The above code would check if the model is created within the last 3 **seconds**. In the future, `Numeric#{ago,until,since,from_now}` should be removed completely, or throw some sort of errors to indicate there are no implicit conversion from `Numeric` to `AS::Duration`. Also fixed & refactor the test cases for Numeric#{ago,since} and AS::Duration#{ago,since}. The original test case had the assertion flipped and the purpose of the test wasn't very clear.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/numeric/time.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/numeric/time.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/numeric/time.rb b/activesupport/lib/active_support/core_ext/numeric/time.rb
index d97ce938c1..704c4248d9 100644
--- a/activesupport/lib/active_support/core_ext/numeric/time.rb
+++ b/activesupport/lib/active_support/core_ext/numeric/time.rb
@@ -63,6 +63,7 @@ class Numeric
# 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
@@ -71,6 +72,7 @@ class Numeric
# 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