diff options
author | Andrey Novikov <envek@envek.name> | 2015-12-27 19:32:31 +0300 |
---|---|---|
committer | Andrey Novikov <envek@envek.name> | 2016-04-28 03:45:05 +0300 |
commit | 434df0016e228a7d51f1ad0c3d1f89faeffbed9a (patch) | |
tree | a4e5f1e5c33cf8ca2fc7e1db8b4dbe5a4e07510c /activesupport/lib/active_support/duration.rb | |
parent | da2dc68c86d419a4db29feb6764a9200f71c45f1 (diff) | |
download | rails-434df0016e228a7d51f1ad0c3d1f89faeffbed9a.tar.gz rails-434df0016e228a7d51f1ad0c3d1f89faeffbed9a.tar.bz2 rails-434df0016e228a7d51f1ad0c3d1f89faeffbed9a.zip |
Change 1.week to create 1 week durations instead of 7 days durations.
This is just to remove astonishment from getting `3600 seconds` from typing `1.hour`.
Diffstat (limited to 'activesupport/lib/active_support/duration.rb')
-rw-r--r-- | activesupport/lib/active_support/duration.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index c717e7f357..47d09f4f5a 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -120,7 +120,7 @@ module ActiveSupport def inspect #:nodoc: parts. reduce(::Hash.new(0)) { |h,(l,r)| h[l] += r; h }. - sort_by {|unit, _ | [:years, :months, :days, :minutes, :seconds].index(unit)}. + sort_by {|unit, _ | [:years, :months, :weeks, :days, :hours, :minutes, :seconds].index(unit)}. map {|unit, val| "#{val} #{val == 1 ? unit.to_s.chop : unit.to_s}"}. to_sentence(locale: ::I18n.default_locale) end @@ -159,6 +159,10 @@ module ActiveSupport if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) + elsif type == :minutes + t.since(sign * number * 60) + elsif type == :hours + t.since(sign * number * 3600) else t.advance(type => sign * number) end |