diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-11-26 10:43:23 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-11-26 10:43:23 -0800 |
commit | 924018ff5cbc7c780b892ffef6a63c232130cc52 (patch) | |
tree | ab9fd1a6db1f85d2e941ae76ecdf39f017021159 /actionpack/lib/action_view/helpers/date_helper.rb | |
parent | 51676652a3568ad09b06385564de4fdcb13af05e (diff) | |
parent | 1a876f622865979ea6415d913adface70716e458 (diff) | |
download | rails-924018ff5cbc7c780b892ffef6a63c232130cc52.tar.gz rails-924018ff5cbc7c780b892ffef6a63c232130cc52.tar.bz2 rails-924018ff5cbc7c780b892ffef6a63c232130cc52.zip |
Merge pull request #8321 from steveklabnik/backport_7997
Add i18n scope to disance_of_time_in_words.
Diffstat (limited to 'actionpack/lib/action_view/helpers/date_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 87e2332c42..cb3e8b9d7f 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -65,12 +65,16 @@ module ActionView # distance_of_time_in_words(Time.now, Time.now) # => less than a minute # def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {}) + options = { + :scope => :'datetime.distance_in_words', + }.merge!(options) + from_time = from_time.to_time if from_time.respond_to?(:to_time) to_time = to_time.to_time if to_time.respond_to?(:to_time) distance_in_minutes = (((to_time - from_time).abs)/60).round distance_in_seconds = ((to_time - from_time).abs).round - I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale| + I18n.with_options :locale => options[:locale], :scope => options[:scope] do |locale| case distance_in_minutes when 0..1 return distance_in_minutes == 0 ? @@ -129,8 +133,8 @@ module ActionView # from_time = Time.now - 3.days - 14.minutes - 25.seconds # time_ago_in_words(from_time) # => 3 days # - def time_ago_in_words(from_time, include_seconds = false) - distance_of_time_in_words(from_time, Time.now, include_seconds) + def time_ago_in_words(from_time, include_seconds = false, options = {}) + distance_of_time_in_words(from_time, Time.now, include_seconds, options) end alias_method :distance_of_time_in_words_to_now, :time_ago_in_words |