From bc1bcddede0c300e9c88f76a66a152814b734981 Mon Sep 17 00:00:00 2001 From: Rob Zolkos & Xavier Noria Date: Sat, 16 Oct 2010 02:22:12 +0200 Subject: implements weeks_ago and prev_week for Date/DateTime/Time [#5122 state:committed] --- .../source/active_support_core_extensions.textile | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 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 dfc4d38112..9b1d264d2c 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2859,9 +2859,9 @@ d.end_of_week # => Sun, 09 May 2010 +beginning_of_week+ is aliased to +monday+ and +at_beginning_of_week+. +end_of_week+ is aliased to +sunday+ and +at_end_of_week+. -h6. +next_week+ +h6. +prev_week+, +next_week+ -+next_week+ receives a symbol with a day name in English (in lowercase, default is +:monday+) and it returns the date corresponding to that day in the next week: +The method +next_week+ receives a symbol with a day name in English (in lowercase, default is +:monday+) and it returns the date corresponding to that day: d = Date.new(2010, 5, 9) # => Sun, 09 May 2010 @@ -2869,6 +2869,14 @@ d.next_week # => Mon, 10 May 2010 d.next_week(:saturday) # => Sat, 15 May 2010 +The method +prev_week+ is analogous: + + +d.prev_week # => Mon, 26 Apr 2010 +d.prev_week(:saturday) # => Sat, 01 May 2010 +d.prev_week(:friday) # => Fri, 30 Apr 2010 + + h6. +beginning_of_month+, +end_of_month+ The methods +beginning_of_month+ and +end_of_month+ return the dates for the beginning and end of the month: @@ -2946,6 +2954,15 @@ Date.new(2010, 4, 30).months_ago(2) # => Sun, 28 Feb 2010 Date.new(2009, 12, 31).months_since(2) # => Sun, 28 Feb 2010 +h6. +weeks_ago+ + +The method +weeks_ago+ works analogously for weeks: + + +Date.new(2010, 5, 24).weeks_ago(1) # => Mon, 17 May 2010 +Date.new(2010, 5, 24).weeks_ago(2) # => Mon, 10 May 2010 + + h6. +advance+ The most generic way to jump to other days is +advance+. This method receives a hash with keys +:years+, +:months+, +:weeks+, +:days+, and returns a date advanced as much as the present keys indicate: @@ -3067,6 +3084,8 @@ yesterday tomorrow beginning_of_week (monday, at_beginning_of_week) end_on_week (at_end_of_week) +weeks_ago +prev_week next_week months_ago months_since @@ -3239,6 +3258,8 @@ beginning_of_day (midnight, at_midnight, at_beginning_of_day) end_of_day beginning_of_week (monday, at_beginning_of_week) end_on_week (at_end_of_week) +weeks_ago +prev_week next_week months_ago months_since -- cgit v1.2.3