Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Distance of time in words should work correct if from time > to_time

  • Loading branch information...
commit 9f2e39a392f539cb39ac6765a43c89ed851de876 1 parent b41b65e
@avakhov avakhov authored committed
View
5 actionpack/lib/action_view/helpers/date_helper.rb
@@ -70,8 +70,9 @@ module DateHelper
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, 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
+ from_time, to_time = to_time, from_time if from_time > to_time
+ distance_in_minutes = ((to_time - from_time)/60).round
+ distance_in_seconds = (to_time - from_time).round
I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
case distance_in_minutes
View
1  actionpack/test/template/date_helper_test.rb
@@ -125,6 +125,7 @@ def test_distance_in_words_with_dates
start_date = Date.new 1982, 12, 3
end_date = Date.new 2010, 11, 30
assert_equal("almost 28 years", distance_of_time_in_words(start_date, end_date))
+ assert_equal("almost 28 years", distance_of_time_in_words(end_date, start_date))
end
def test_distance_in_words_with_integers
Please sign in to comment.
Something went wrong with that request. Please try again.