aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-05-09 12:45:21 +0300
committerXavier Noria <fxn@hashref.com>2010-05-09 12:45:21 +0300
commit1ff3d951e620ddeeb97e87e2024391470e886467 (patch)
tree4115953e0a4e7c2928742fb2231f1ac68cab7a70 /railties/guides/source/active_support_core_extensions.textile
parent08d991ad409295a2d91b10bca4c7080fdbe7b5b9 (diff)
downloadrails-1ff3d951e620ddeeb97e87e2024391470e886467.tar.gz
rails-1ff3d951e620ddeeb97e87e2024391470e886467.tar.bz2
rails-1ff3d951e620ddeeb97e87e2024391470e886467.zip
AS guide: more date calculation utilities
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile60
1 files changed, 59 insertions, 1 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index d321e3db72..b7b5f47eef 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -2680,7 +2680,7 @@ d.next_year # => Wed, 28 Feb 2001
h6. +last_month+, +next_month+
-The methods +last_month+ and +next_month+ return the a date with the same day in the last or next month:
+The methods +last_month+ and +next_month+ return the date with the same day in the last or next month:
<ruby>
d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
@@ -2697,6 +2697,64 @@ Date.new(2000, 5, 31).next_month # => Fri, 30 Jun 2000
Date.new(2000, 1, 31).next_month # => Tue, 29 Feb 2000
</ruby>
+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:
+
+<ruby>
+d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
+d.beginning_of_week # => Mon, 03 May 2010
+d.end_of_week # => Sun, 09 May 2010
+</ruby>
+
++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+
+
++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:
+
+<ruby>
+d = Date.new(2010, 5, 9) # => Sun, 09 May 2010
+d.next_week # => Mon, 10 May 2010
+d.next_week(:saturday) # => Sat, 15 May 2010
+</ruby>
+
+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:
+
+<ruby>
+d = Date.new(2010, 5, 9) # => Sun, 09 May 2010
+d.beginning_of_month # => Sat, 01 May 2010
+d.end_of_month # => Mon, 31 May 2010
+</ruby>
+
++beginning_of_month+ is aliased to +at_beginning_of_month+, and +end_of_month+ is aliased to +at_end_of_month+.
+
+h6. +beginning_of_quarter+, +end_of_quarter+
+
+The methods +beginning_of_quarter+ and +end_of_quarter+ return the dates for the beginning and end of the quarter of the receiver's calendar year:
+
+<ruby>
+d = Date.new(2010, 5, 9) # => Sun, 09 May 2010
+d.beginning_of_quarter # => Thu, 01 Apr 2010
+d.end_of_quarter # => Wed, 30 Jun 2010
+</ruby>
+
++beginning_of_quarter+ is aliased to +at_beginning_of_quarter+, and +end_of_quarter+ is aliased to +at_end_of_quarter+.
+
+h6. +beginning_of_year+, +end_of_year+
+
+The methods +beginning_of_year+ and +end_of_year+ return the dates for the beginning and end of the year:
+
+<ruby>
+d = Date.new(2010, 5, 9) # => Sun, 09 May 2010
+d.beginning_of_year # => Fri, 01 Jan 2010
+d.end_of_year # => Fri, 31 Dec 2010
+</ruby>
+
++beginning_of_year+ is aliased to +at_beginning_of_year+, and +end_of_year+ is aliased to +at_end_of_year+.
+
h4. Conversions
h3. Extensions to +DateTime+