diff options
author | bogdanvlviv <bogdanvlviv@gmail.com> | 2017-09-16 19:06:45 +0300 |
---|---|---|
committer | bogdanvlviv <bogdanvlviv@gmail.com> | 2017-10-24 21:17:54 +0300 |
commit | ee9d81837b5eba9d5ec869ae7601d7ffce763e3e (patch) | |
tree | dcb28197ee2c901788ae4431bb136e0994e3d209 /activesupport/lib | |
parent | f2c1e3a793570584d9708aaee387214bc3543530 (diff) | |
download | rails-ee9d81837b5eba9d5ec869ae7601d7ffce763e3e.tar.gz rails-ee9d81837b5eba9d5ec869ae7601d7ffce763e3e.tar.bz2 rails-ee9d81837b5eba9d5ec869ae7601d7ffce763e3e.zip |
Allows pass argument for `Time#prev_year` and `Time#next_year`.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_and_time/calculations.rb | 14 |
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 59c87b9c06..061b79e098 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 @@ -198,9 +198,9 @@ module DateAndTime months_since(3) end - # Short-hand for years_since(1). - def next_year - years_since(1) + # Returns a new date/time the specified number of years in the future. + def next_year(years = 1) + advance(years: years) end # Returns a new date/time representing the given day in the previous week. @@ -239,11 +239,15 @@ module DateAndTime end alias_method :last_quarter, :prev_quarter + # Returns a new date/time the specified number of years ago. + def prev_year(years = 1) + advance(years: -years) + end + # Short-hand for years_ago(1). - def prev_year + def last_year years_ago(1) end - alias_method :last_year, :prev_year # Returns the number of days to the start of the week on the given day. # Week is assumed to start on +start_day+, default is |