From 4c53f58a0fc89dd8bf0ea9abd40b7a198dd13b99 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Tue, 6 Jan 2015 05:30:04 -0500 Subject: Add #prev_day and #next_day as counterparts to #yesterday and #tomorrow for Date, Time, and DateTime --- .../core_ext/date_and_time/calculations.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/date_and_time') 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 -- cgit v1.2.3