diff options
author | George Claghorn <george.claghorn@gmail.com> | 2015-01-06 05:30:04 -0500 |
---|---|---|
committer | George Claghorn <george.claghorn@gmail.com> | 2015-01-06 05:43:41 -0500 |
commit | 4c53f58a0fc89dd8bf0ea9abd40b7a198dd13b99 (patch) | |
tree | 9878b6428d0c6f7087050d3025d83785cd54282f /activesupport/lib | |
parent | b6d0d0d106b5cd59f8da3f893b29a05bc85ac14e (diff) | |
download | rails-4c53f58a0fc89dd8bf0ea9abd40b7a198dd13b99.tar.gz rails-4c53f58a0fc89dd8bf0ea9abd40b7a198dd13b99.tar.bz2 rails-4c53f58a0fc89dd8bf0ea9abd40b7a198dd13b99.zip |
Add #prev_day and #next_day as counterparts to #yesterday and #tomorrow for Date, Time, and DateTime
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_and_time/calculations.rb | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb index 5f16794926..e4bfd9f7c5 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb @@ -13,12 +13,22 @@ module DateAndTime # Returns a new date/time representing yesterday. def yesterday - advance(:days => -1) + advance(days: -1) + end + + # Returns a new date/time representing the previous day. + def prev_day + advance(days: -1) end # Returns a new date/time representing tomorrow. def tomorrow - advance(:days => 1) + advance(days: 1) + end + + # Returns a new date/time representing the next day. + def next_day + advance(days: 1) end # Returns true if the date/time is today. @@ -125,10 +135,10 @@ module DateAndTime # Returns a new date/time representing the next weekday. def next_weekday - if tomorrow.on_weekend? + if next_day.on_weekend? next_week(:monday, same_time: true) else - tomorrow + next_day end end @@ -159,10 +169,10 @@ module DateAndTime # Returns a new date/time representing the previous weekday. def prev_weekday - if yesterday.on_weekend? + if prev_day.on_weekend? copy_time_to(beginning_of_week(:friday)) else - yesterday + prev_day end end alias_method :last_weekday, :prev_weekday |