diff options
author | Xavier Noria <fxn@hashref.com> | 2012-02-28 01:37:19 -0800 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2012-02-28 01:37:19 -0800 |
commit | 699ba8ab52973bf0499643235f162734fb644ab7 (patch) | |
tree | 51f6081921c27eaf906460a208efa46f03467909 /activesupport/lib | |
parent | 43faccf45fed33a5e529d0a156f958b9d8b785b7 (diff) | |
parent | d6366625e04c516bf5f4bd6f561c3bb1945b0c82 (diff) | |
download | rails-699ba8ab52973bf0499643235f162734fb644ab7.tar.gz rails-699ba8ab52973bf0499643235f162734fb644ab7.tar.bz2 rails-699ba8ab52973bf0499643235f162734fb644ab7.zip |
Merge pull request #4284 from mattdbridges/time_calculation_aliases
Added aliases for prev_year, prev_month, and prev_week in Time and Date calculations
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date/calculations.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 3 |
2 files changed, 10 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 af78226c21..6d4270f8b0 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -182,6 +182,13 @@ class Date result = (self - 7).beginning_of_week + DAYS_INTO_WEEK[day] self.acts_like?(:time) ? result.change(:hour => 0) : result end + alias :last_week :prev_week + + # Alias of prev_month + alias :last_month :prev_month + + # Alias of prev_year + alias :last_year :prev_year # Returns a new Date/DateTime representing the start of the given day in next week (default is :monday). def next_week(day = :monday) diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index dd2a21fe2a..5076697c04 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -145,6 +145,7 @@ class Time def prev_year years_ago(1) end + alias_method :last_year, :prev_year # Short-hand for years_since(1) def next_year @@ -155,6 +156,7 @@ class Time def prev_month months_ago(1) end + alias_method :last_month, :prev_month # Short-hand for months_since(1) def next_month @@ -199,6 +201,7 @@ class Time def prev_week(day = :monday) ago(1.week).beginning_of_week.since(DAYS_INTO_WEEK[day].day).change(:hour => 0) end + alias_method :last_week, :prev_week # Returns a new Time representing the start of the given day in next week (default is :monday). def next_week(day = :monday) |