mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow distance_of_time_in_words to work with any value that responds to #to_time (like dates) #969
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1420 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
3cb869eab6
commit
ed7bfc9662
3 changed files with 12 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Allow distance_of_time_in_words to work with any value that responds to #to_time (like dates) #969
|
||||||
|
|
||||||
* Support :render option for :verify #1440 [TobiasLuetke]
|
* Support :render option for :verify #1440 [TobiasLuetke]
|
||||||
|
|
||||||
* Updated vendor copy of html-scanner lib to 0.5.1, for bug fixes and optimizations
|
* Updated vendor copy of html-scanner lib to 0.5.1, for bug fixes and optimizations
|
||||||
|
|
|
@ -17,6 +17,8 @@ module ActionView
|
||||||
# "about 1 hour". See the source for the complete wording list.
|
# "about 1 hour". See the source for the complete wording list.
|
||||||
#Set <tt>include_seconds</tt> to true if you want more detailed approximations if distance < 1 minute
|
#Set <tt>include_seconds</tt> to true if you want more detailed approximations if distance < 1 minute
|
||||||
def distance_of_time_in_words(from_time, to_time, include_seconds = false)
|
def distance_of_time_in_words(from_time, to_time, include_seconds = false)
|
||||||
|
from_time = from_time.to_time
|
||||||
|
to_time = to_time.to_time
|
||||||
distance_in_minutes = ((to_time - from_time) / 60).round.abs
|
distance_in_minutes = ((to_time - from_time) / 60).round.abs
|
||||||
distance_in_seconds = ((to_time - from_time)).round.abs
|
distance_in_seconds = ((to_time - from_time)).round.abs
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
|
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
|
||||||
|
require File.dirname(__FILE__) + "/../abstract_unit"
|
||||||
|
|
||||||
class DateHelperTest < Test::Unit::TestCase
|
class DateHelperTest < Test::Unit::TestCase
|
||||||
include ActionView::Helpers::DateHelper
|
include ActionView::Helpers::DateHelper
|
||||||
|
@ -31,6 +32,13 @@ class DateHelperTest < Test::Unit::TestCase
|
||||||
assert_equal "less than 20 seconds", distance_of_time_in_words(Time.mktime(2004, 3, 6, 21, 41, 38), from, true)
|
assert_equal "less than 20 seconds", distance_of_time_in_words(Time.mktime(2004, 3, 6, 21, 41, 38), from, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_distance_in_words_date
|
||||||
|
start_date = Date.new 1904, 1, 31
|
||||||
|
end_date = Date.new 1906, 4, 17
|
||||||
|
assert_not_equal("13 minutes",
|
||||||
|
distance_of_time_in_words(start_date, end_date))
|
||||||
|
end
|
||||||
|
|
||||||
def test_select_day
|
def test_select_day
|
||||||
expected = %(<select name="date[day]">\n)
|
expected = %(<select name="date[day]">\n)
|
||||||
expected <<
|
expected <<
|
||||||
|
|
Loading…
Reference in a new issue