aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorbogdanvlviv <bogdanvlviv@gmail.com>2017-09-16 18:36:49 +0300
committerbogdanvlviv <bogdanvlviv@gmail.com>2017-10-24 21:17:54 +0300
commitf2c1e3a793570584d9708aaee387214bc3543530 (patch)
tree71049e85a851592601961f7f0dd0e38f6ac62215 /activesupport/lib
parent61ac2167eff741bffb44aec231f4ea13d004134e (diff)
downloadrails-f2c1e3a793570584d9708aaee387214bc3543530.tar.gz
rails-f2c1e3a793570584d9708aaee387214bc3543530.tar.bz2
rails-f2c1e3a793570584d9708aaee387214bc3543530.zip
Allows pass argument for `Time#prev_month` and `Time#next_month`
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/date_and_time/calculations.rb14
1 files changed, 9 insertions, 5 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 9b5477b199..59c87b9c06 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
@@ -188,9 +188,9 @@ module DateAndTime
end
end
- # Short-hand for months_since(1).
- def next_month
- months_since(1)
+ # Returns a new date/time the specified number of months in the future.
+ def next_month(months = 1)
+ advance(months: months)
end
# Short-hand for months_since(3)
@@ -223,11 +223,15 @@ module DateAndTime
end
alias_method :last_weekday, :prev_weekday
+ # Returns a new date/time the specified number of months ago.
+ def prev_month(months = 1)
+ advance(months: -months)
+ end
+
# Short-hand for months_ago(1).
- def prev_month
+ def last_month
months_ago(1)
end
- alias_method :last_month, :prev_month
# Short-hand for months_ago(3).
def prev_quarter