diff options
author | paranoiase Kang <paranoiase@gmail.com> | 2012-05-20 14:33:58 +0900 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-20 11:39:11 -0300 |
commit | 2773257ac64c82affae527436b08e6d627853c1d (patch) | |
tree | bbe0186dc87c3039abd13d59c39f8eee8bba14b1 /activesupport/lib/active_support | |
parent | 1bb2f5a8316c3e94b47b9cfb8fa519e1b1238869 (diff) | |
download | rails-2773257ac64c82affae527436b08e6d627853c1d.tar.gz rails-2773257ac64c82affae527436b08e6d627853c1d.tar.bz2 rails-2773257ac64c82affae527436b08e6d627853c1d.zip |
Add prev_quarter and next_quarter method in Time/Date/DateTime
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date/calculations.rb | 11 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 11 |
2 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index 8a7eb6bc6b..7fe4161fb4 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -202,6 +202,17 @@ class Date acts_like?(:time) ? result.change(:hour => 0) : result end + # Short-hand for months_ago(3) + def prev_quarter + months_ago(3) + end + alias_method :last_quarter, :prev_quarter + + # Short-hand for months_since(3) + def next_quarter + months_since(3) + end + # Returns a new Date/DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00) def beginning_of_month acts_like?(:time) ? change(:day => 1, :hour => 0) : change(:day => 1) diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 92b8417150..28c8b53b78 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -186,6 +186,17 @@ class Time months_since(1) end + # Short-hand for months_ago(3) + def prev_quarter + months_ago(3) + end + alias_method :last_quarter, :prev_quarter + + # Short-hand for months_since(3) + def next_quarter + months_since(3) + end + # Returns number of days to start of this week, week starts on start_day (default is :monday). def days_to_week_start(start_day = :monday) start_day_number = DAYS_INTO_WEEK[start_day] |