Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 25ec61330b08975ba01577cde5e59aea04e7926b 1 parent 9d99e61
Xavier Noria authored May 19, 2010
2  activesupport/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *2.3.6 (pending)*
2 2
 
  3
+* 1.9 compat: deprecated last_(month|year) in favor of prev_(month|year). [fxn]
  4
+
3 5
 * Deprecated Array#rand in favor of Array#random_element. [Santiago Pastorino, Rizwan Reza]
4 6
 
5 7
 * Added Object#presence that returns the object if it's #present? otherwise returns nil [DHH/Colin Kelley]
18  activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -135,20 +135,30 @@ def years_since(years)
135 135
           advance(:years => years)
136 136
         end
137 137
 
  138
+        def last_year # :nodoc:
  139
+          ActiveSupport::Deprecation.warn("Date#last_year is deprecated and has been removed in Rails 3, please use Date#prev_year instead", caller)
  140
+          prev_year
  141
+        end
  142
+
138 143
         # Short-hand for years_ago(1)
139  
-        def last_year
  144
+        def prev_year
140 145
           years_ago(1)
141  
-        end
  146
+        end unless method_defined?(:prev_year)
142 147
 
143 148
         # Short-hand for years_since(1)
144 149
         def next_year
145 150
           years_since(1)
146 151
         end
147 152
 
  153
+        def last_month # :nodoc:
  154
+          ActiveSupport::Deprecation.warn("Date#last_month is deprecated and has been removed in Rails 3, please use Date#prev_month instead", caller)
  155
+          prev_month
  156
+        end
  157
+
148 158
         # Short-hand for months_ago(1)
149  
-        def last_month
  159
+        def prev_month
150 160
           months_ago(1)
151  
-        end
  161
+        end unless method_defined?(:prev_month)
152 162
 
153 163
         # Short-hand for months_since(1)
154 164
         def next_month
13  activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -157,8 +157,13 @@ def years_since(years)
157 157
           advance(:years => years)
158 158
         end
159 159
 
  160
+        def last_year # :nodoc:
  161
+          ActiveSupport::Deprecation.warn("Time#last_year is deprecated and has been removed in Rails 3, please use Time#prev_year instead", caller)
  162
+          prev_year
  163
+        end
  164
+
160 165
         # Short-hand for years_ago(1)
161  
-        def last_year
  166
+        def prev_year
162 167
           years_ago(1)
163 168
         end
164 169
 
@@ -167,9 +172,13 @@ def next_year
167 172
           years_since(1)
168 173
         end
169 174
 
  175
+        def last_month # :nodoc:
  176
+          ActiveSupport::Deprecation.warn("Time#last_month is deprecated and has been removed in Rails 3, please use Time#prev_month instead", caller)
  177
+          prev_month
  178
+        end
170 179
 
171 180
         # Short-hand for months_ago(1)
172  
-        def last_month
  181
+        def prev_month
173 182
           months_ago(1)
174 183
         end
175 184
 
18  activesupport/test/core_ext/date_ext_test.rb
... ...
@@ -1,6 +1,6 @@
1 1
 require 'abstract_unit'
2 2
 
3  
-class DateExtCalculationsTest < Test::Unit::TestCase
  3
+class DateExtCalculationsTest < ActiveSupport::TestCase
4 4
   def test_to_s
5 5
     date = Date.new(2005, 2, 21)
6 6
     assert_equal "2005-02-21",          date.to_s
@@ -130,8 +130,12 @@ def test_years_since
130 130
     assert_equal Date.new(2005,2,28), Date.new(2004,2,29).years_since(1) # 1 year since leap day
131 131
   end
132 132
 
133  
-  def test_last_year
134  
-    assert_equal Date.new(2004,6,5),  Date.new(2005,6,5).last_year
  133
+  def test_last_year_is_deprecated
  134
+    assert_deprecated { Date.today.last_year }
  135
+  end
  136
+
  137
+  def test_prev_year
  138
+    assert_equal Date.new(2004,6,5),  Date.new(2005,6,5).prev_year
135 139
   end
136 140
 
137 141
   def test_next_year
@@ -170,8 +174,12 @@ def test_next_month_on_31st
170 174
     assert_equal Date.new(2005, 9, 30), Date.new(2005, 8, 31).next_month
171 175
   end
172 176
 
173  
-  def test_last_month_on_31st
174  
-    assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).last_month
  177
+  def test_last_month_is_deprecated
  178
+    assert_deprecated { Date.today.last_month }
  179
+  end
  180
+
  181
+  def test_prev_month_on_31st
  182
+    assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).prev_month
175 183
   end
176 184
 
177 185
   def test_yesterday_constructor
8  activesupport/test/core_ext/date_time_ext_test.rb
@@ -121,8 +121,8 @@ def test_years_since
121 121
     assert_equal DateTime.civil(2005,2,28,10), DateTime.civil(2004,2,29,10,0,0).years_since(1) # 1 year since leap day
122 122
   end
123 123
 
124  
-  def test_last_year
125  
-    assert_equal DateTime.civil(2004,6,5,10),  DateTime.civil(2005,6,5,10,0,0).last_year
  124
+  def test_prev_year
  125
+    assert_equal DateTime.civil(2004,6,5,10),  DateTime.civil(2005,6,5,10,0,0).prev_year
126 126
   end
127 127
 
128 128
   def test_next_year
@@ -194,8 +194,8 @@ def test_next_month_on_31st
194 194
     assert_equal DateTime.civil(2005, 9, 30), DateTime.civil(2005, 8, 31).next_month
195 195
   end
196 196
 
197  
-  def test_last_month_on_31st
198  
-    assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).last_month
  197
+  def test_prev_month_on_31st
  198
+    assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).prev_month
199 199
   end
200 200
 
201 201
   def test_xmlschema
18  activesupport/test/core_ext/time_ext_test.rb
... ...
@@ -1,6 +1,6 @@
1 1
 require 'abstract_unit'
2 2
 
3  
-class TimeExtCalculationsTest < Test::Unit::TestCase
  3
+class TimeExtCalculationsTest < ActiveSupport::TestCase
4 4
   def test_seconds_since_midnight
5 5
     assert_equal 1,Time.local(2005,1,1,0,0,1).seconds_since_midnight
6 6
     assert_equal 60,Time.local(2005,1,1,0,1,0).seconds_since_midnight
@@ -165,8 +165,12 @@ def test_years_since
165 165
     # assert_equal Time.local(2182,6,5,10),  Time.local(2005,6,5,10,0,0).years_since(177)
166 166
   end
167 167
 
168  
-  def test_last_year
169  
-    assert_equal Time.local(2004,6,5,10),  Time.local(2005,6,5,10,0,0).last_year
  168
+  def test_last_year_is_deprecated
  169
+    assert_deprecated { Time.now.last_year }
  170
+  end
  171
+
  172
+  def test_prev_year
  173
+    assert_equal Time.local(2004,6,5,10),  Time.local(2005,6,5,10,0,0).prev_year
170 174
   end
171 175
 
172 176
   def test_next_year
@@ -562,12 +566,16 @@ def test_local_time
562 566
     end
563 567
   end
564 568
 
  569
+  def test_last_month_is_deprecated
  570
+    assert_deprecated { Time.now.last_month }
  571
+  end
  572
+
565 573
   def test_next_month_on_31st
566 574
     assert_equal Time.local(2005, 9, 30), Time.local(2005, 8, 31).next_month
567 575
   end
568 576
 
569  
-  def test_last_month_on_31st
570  
-    assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).last_month
  577
+  def test_prev_month_on_31st
  578
+    assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).prev_month
571 579
   end
572 580
 
573 581
   def test_xmlschema_is_available

0 notes on commit 25ec613

Please sign in to comment.
Something went wrong with that request. Please try again.