From 2203c781a7dfa8b0c8b6c97cd318d941f9fbb26c Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 12 May 2010 23:04:17 +0200 Subject: defines prev_(month|year) in Date and Time to ease transition to 1.9, and deprecates last_(month|year) --- .../source/active_support_core_extensions.textile | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'railties/guides/source/active_support_core_extensions.textile') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index b7b5f47eef..fed0c25e8e 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2660,13 +2660,13 @@ Active Support defines +Date.current+ to be today in the current time zone. That h5. Named dates -h6. +last_year+, +next_year+ +h6. +prev_year+, +next_year+ -The methods +last_year+ and +next_year+ return a date with the same day/month in the last or next year: +In Ruby 1.9 +prev_year+ and +next_year+ return a date with the same day/month in the last or next year: d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 -d.last_year # => Fri, 08 May 2009 +d.prev_year # => Fri, 08 May 2009 d.next_year # => Sun, 08 May 2011 @@ -2674,29 +2674,33 @@ If date is the 29th of February of a leap year, you obtain the 28th: d = Date.new(2000, 2, 29) # => Tue, 29 Feb 2000 -d.last_year # => Sun, 28 Feb 1999 +d.prev_year # => Sun, 28 Feb 1999 d.next_year # => Wed, 28 Feb 2001 -h6. +last_month+, +next_month+ +Active Support defines these methods as well for Ruby 1.8. -The methods +last_month+ and +next_month+ return the date with the same day in the last or next month: +h6. +prev_month+, +next_month+ + +In Ruby 1.9 +prev_month+ and +next_month+ return the date with the same day in the last or next month: d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 -d.last_month # => Thu, 08 Apr 2010 +d.prev_month # => Thu, 08 Apr 2010 d.next_month # => Tue, 08 Jun 2010 If such a day does not exist, the last day of the corresponding month is returned: -Date.new(2000, 5, 31).last_month # => Sun, 30 Apr 2000 -Date.new(2000, 3, 31).last_month # => Tue, 29 Feb 2000 +Date.new(2000, 5, 31).prev_month # => Sun, 30 Apr 2000 +Date.new(2000, 3, 31).prev_month # => Tue, 29 Feb 2000 Date.new(2000, 5, 31).next_month # => Fri, 30 Jun 2000 Date.new(2000, 1, 31).next_month # => Tue, 29 Feb 2000 +Active Support defines these methods as well for Ruby 1.8. + h6. +beginning_of_week+, +end_of_week+ The methods +beginning_of_week+ and +end_of_week+ return the dates for the beginning and end of week, assuming weeks start on Monday: -- cgit v1.2.3