diff options
author | Matt Bridges <mbridges.91@gmail.com> | 2012-01-03 19:53:13 -0600 |
---|---|---|
committer | Matt Bridges <mbridges.91@gmail.com> | 2012-02-21 16:27:08 -0600 |
commit | d6366625e04c516bf5f4bd6f561c3bb1945b0c82 (patch) | |
tree | 34c9ada6ee0e422235ec3cfeed7439806ebdfa50 /activesupport/lib/active_support | |
parent | 7cfd1bd76a41bea528c945d821a9fbc3902af479 (diff) | |
download | rails-d6366625e04c516bf5f4bd6f561c3bb1945b0c82.tar.gz rails-d6366625e04c516bf5f4bd6f561c3bb1945b0c82.tar.bz2 rails-d6366625e04c516bf5f4bd6f561c3bb1945b0c82.zip |
Adding :last_week, :last_month, and :last_year aliases to Time and Date
core extensions
Diffstat (limited to 'activesupport/lib/active_support')
-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 5e433f5dd9..5cf2715753 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) |