diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2019-01-18 08:27:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-18 08:27:32 -0500 |
commit | fac52ee506097e7b97501c50e13c0782549f1410 (patch) | |
tree | 3e9381e4b95e073cbbb7baf102bbdc0514812983 | |
parent | 7235e8493571d2f4a78f70eb8f32d4ae06bfa713 (diff) | |
parent | f3dd1791625313630fc8da2721c58b4780d64a13 (diff) | |
download | rails-fac52ee506097e7b97501c50e13c0782549f1410.tar.gz rails-fac52ee506097e7b97501c50e13c0782549f1410.tar.bz2 rails-fac52ee506097e7b97501c50e13c0782549f1410.zip |
Merge pull request #34972 from krzysiek1507/fix/date-advance-performance
Faster and better memory efficient Date#advance
-rw-r--r-- | activesupport/lib/active_support/core_ext/date/calculations.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index 1cd7acb05d..d03a8d3997 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -110,12 +110,13 @@ class Date # Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with # any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>. def advance(options) - options = options.dup d = self - d = d >> options.delete(:years) * 12 if options[:years] - d = d >> options.delete(:months) if options[:months] - d = d + options.delete(:weeks) * 7 if options[:weeks] - d = d + options.delete(:days) if options[:days] + + d = d >> options[:years] * 12 if options[:years] + d = d >> options[:months] if options[:months] + d = d + options[:weeks] * 7 if options[:weeks] + d = d + options[:days] if options[:days] + d end |