diff options
author | Jeremy Daer <jeremydaer@gmail.com> | 2016-04-17 23:26:22 -0700 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2016-04-17 23:42:42 -0700 |
commit | 7254517f1efe896c53330d4ac0c4a48cd6559614 (patch) | |
tree | 43d32f68150aad890ee23bf73c76236a9531747e /activesupport/lib/active_support/core_ext/numeric/time.rb | |
parent | cdce6131500820c9fd88709c46d84e57a9fd3f90 (diff) | |
parent | 1bf9fe75a6473cb7501cae544cab772713e68cef (diff) | |
download | rails-7254517f1efe896c53330d4ac0c4a48cd6559614.tar.gz rails-7254517f1efe896c53330d4ac0c4a48cd6559614.tar.bz2 rails-7254517f1efe896c53330d4ac0c4a48cd6559614.zip |
Merge pull request #22806 from Envek/solid_durations
Introduce weeks and hours periods to Duration.
Change 1.week to create a 1 week duration instead of 7 days and 1.hour
to create a 1 hour duration instead of 3600 seconds.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/numeric/time.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/numeric/time.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/numeric/time.rb b/activesupport/lib/active_support/core_ext/numeric/time.rb index 6c4a975495..c6ece22f8d 100644 --- a/activesupport/lib/active_support/core_ext/numeric/time.rb +++ b/activesupport/lib/active_support/core_ext/numeric/time.rb @@ -25,17 +25,17 @@ class Numeric # Returns a Duration instance matching the number of minutes provided. # - # 2.minutes # => 120 seconds + # 2.minutes # => 2 minutes def minutes - ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]]) + ActiveSupport::Duration.new(self * 60, [[:minutes, self]]) end alias :minute :minutes # Returns a Duration instance matching the number of hours provided. # - # 2.hours # => 7_200 seconds + # 2.hours # => 2 hours def hours - ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]]) + ActiveSupport::Duration.new(self * 3600, [[:hours, self]]) end alias :hour :hours @@ -49,17 +49,17 @@ class Numeric # Returns a Duration instance matching the number of weeks provided. # - # 2.weeks # => 14 days + # 2.weeks # => 2 weeks def weeks - ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]]) + ActiveSupport::Duration.new(self * 7.days, [[:weeks, self]]) end alias :week :weeks # Returns a Duration instance matching the number of fortnights provided. # - # 2.fortnights # => 28 days + # 2.fortnights # => 4 weeks def fortnights - ActiveSupport::Duration.new(self * 2.weeks, [[:days, self * 14]]) + ActiveSupport::Duration.new(self * 2.weeks, [[:weeks, self * 2]]) end alias :fortnight :fortnights |