Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

1.9 compat: deprecated last_(month|year) in favor of prev_(month|year)

  • Loading branch information...
commit 25ec61330b08975ba01577cde5e59aea04e7926b 1 parent 9d99e61
@fxn fxn authored
View
2  activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*2.3.6 (pending)*
+* 1.9 compat: deprecated last_(month|year) in favor of prev_(month|year). [fxn]
+
* Deprecated Array#rand in favor of Array#random_element. [Santiago Pastorino, Rizwan Reza]
* Added Object#presence that returns the object if it's #present? otherwise returns nil [DHH/Colin Kelley]
View
18 activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -135,20 +135,30 @@ def years_since(years)
advance(:years => years)
end
+ def last_year # :nodoc:
+ ActiveSupport::Deprecation.warn("Date#last_year is deprecated and has been removed in Rails 3, please use Date#prev_year instead", caller)
+ prev_year
+ end
+
# Short-hand for years_ago(1)
- def last_year
+ def prev_year
years_ago(1)
- end
+ end unless method_defined?(:prev_year)
# Short-hand for years_since(1)
def next_year
years_since(1)
end
+ def last_month # :nodoc:
+ ActiveSupport::Deprecation.warn("Date#last_month is deprecated and has been removed in Rails 3, please use Date#prev_month instead", caller)
+ prev_month
+ end
+
# Short-hand for months_ago(1)
- def last_month
+ def prev_month
months_ago(1)
- end
+ end unless method_defined?(:prev_month)
# Short-hand for months_since(1)
def next_month
View
13 activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -157,8 +157,13 @@ def years_since(years)
advance(:years => years)
end
+ def last_year # :nodoc:
+ ActiveSupport::Deprecation.warn("Time#last_year is deprecated and has been removed in Rails 3, please use Time#prev_year instead", caller)
+ prev_year
+ end
+
# Short-hand for years_ago(1)
- def last_year
+ def prev_year
years_ago(1)
end
@@ -167,9 +172,13 @@ def next_year
years_since(1)
end
+ def last_month # :nodoc:
+ ActiveSupport::Deprecation.warn("Time#last_month is deprecated and has been removed in Rails 3, please use Time#prev_month instead", caller)
+ prev_month
+ end
# Short-hand for months_ago(1)
- def last_month
+ def prev_month
months_ago(1)
end
View
18 activesupport/test/core_ext/date_ext_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class DateExtCalculationsTest < Test::Unit::TestCase
+class DateExtCalculationsTest < ActiveSupport::TestCase
def test_to_s
date = Date.new(2005, 2, 21)
assert_equal "2005-02-21", date.to_s
@@ -130,8 +130,12 @@ def test_years_since
assert_equal Date.new(2005,2,28), Date.new(2004,2,29).years_since(1) # 1 year since leap day
end
- def test_last_year
- assert_equal Date.new(2004,6,5), Date.new(2005,6,5).last_year
+ def test_last_year_is_deprecated
+ assert_deprecated { Date.today.last_year }
+ end
+
+ def test_prev_year
+ assert_equal Date.new(2004,6,5), Date.new(2005,6,5).prev_year
end
def test_next_year
@@ -170,8 +174,12 @@ def test_next_month_on_31st
assert_equal Date.new(2005, 9, 30), Date.new(2005, 8, 31).next_month
end
- def test_last_month_on_31st
- assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).last_month
+ def test_last_month_is_deprecated
+ assert_deprecated { Date.today.last_month }
+ end
+
+ def test_prev_month_on_31st
+ assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).prev_month
end
def test_yesterday_constructor
View
8 activesupport/test/core_ext/date_time_ext_test.rb
@@ -121,8 +121,8 @@ def test_years_since
assert_equal DateTime.civil(2005,2,28,10), DateTime.civil(2004,2,29,10,0,0).years_since(1) # 1 year since leap day
end
- def test_last_year
- assert_equal DateTime.civil(2004,6,5,10), DateTime.civil(2005,6,5,10,0,0).last_year
+ def test_prev_year
+ assert_equal DateTime.civil(2004,6,5,10), DateTime.civil(2005,6,5,10,0,0).prev_year
end
def test_next_year
@@ -194,8 +194,8 @@ def test_next_month_on_31st
assert_equal DateTime.civil(2005, 9, 30), DateTime.civil(2005, 8, 31).next_month
end
- def test_last_month_on_31st
- assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).last_month
+ def test_prev_month_on_31st
+ assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).prev_month
end
def test_xmlschema
View
18 activesupport/test/core_ext/time_ext_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class TimeExtCalculationsTest < Test::Unit::TestCase
+class TimeExtCalculationsTest < ActiveSupport::TestCase
def test_seconds_since_midnight
assert_equal 1,Time.local(2005,1,1,0,0,1).seconds_since_midnight
assert_equal 60,Time.local(2005,1,1,0,1,0).seconds_since_midnight
@@ -165,8 +165,12 @@ def test_years_since
# assert_equal Time.local(2182,6,5,10), Time.local(2005,6,5,10,0,0).years_since(177)
end
- def test_last_year
- assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).last_year
+ def test_last_year_is_deprecated
+ assert_deprecated { Time.now.last_year }
+ end
+
+ def test_prev_year
+ assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).prev_year
end
def test_next_year
@@ -562,12 +566,16 @@ def test_local_time
end
end
+ def test_last_month_is_deprecated
+ assert_deprecated { Time.now.last_month }
+ end
+
def test_next_month_on_31st
assert_equal Time.local(2005, 9, 30), Time.local(2005, 8, 31).next_month
end
- def test_last_month_on_31st
- assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).last_month
+ def test_prev_month_on_31st
+ assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).prev_month
end
def test_xmlschema_is_available
Please sign in to comment.
Something went wrong with that request. Please try again.