1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #9334 from NARKOZ/time_tag

use ISO 8601 format in time_tag helper
This commit is contained in:
Andrew White 2013-02-21 23:33:36 -08:00
commit 31f807c7aa
2 changed files with 21 additions and 19 deletions

View file

@ -642,6 +642,8 @@ module ActionView
# <time datetime="2010-11-03">Yesterday</time>
# time_tag Date.today, pubdate: true # =>
# <time datetime="2010-11-04" pubdate="pubdate">November 04, 2010</time>
# time_tag Date.today, datetime: Date.today.strftime('%G-W%V') # =>
# <time datetime="2010-W44">November 04, 2010</time>
#
# <%= time_tag Time.now do %>
# <span>Right now</span>
@ -651,7 +653,7 @@ module ActionView
options = args.extract_options!
format = options.delete(:format) || :long
content = args.first || I18n.l(date_or_time, :format => format)
datetime = date_or_time.acts_like?(:time) ? date_or_time.xmlschema : date_or_time.rfc3339
datetime = date_or_time.acts_like?(:time) ? date_or_time.xmlschema : date_or_time.iso8601
content_tag(:time, content, options.reverse_merge(:datetime => datetime), &block)
end

View file

@ -3160,14 +3160,14 @@ class DateHelperTest < ActionView::TestCase
end
def test_time_tag_with_date
date = Date.today
expected = "<time datetime=\"#{date.rfc3339}\">#{I18n.l(date, :format => :long)}</time>"
date = Date.new(2013, 2, 20)
expected = '<time datetime="2013-02-20">February 20, 2013</time>'
assert_equal expected, time_tag(date)
end
def test_time_tag_with_time
time = Time.now
expected = "<time datetime=\"#{time.xmlschema}\">#{I18n.l(time, :format => :long)}</time>"
time = Time.new(2013, 2, 20, 0, 0, 0, '+00:00')
expected = '<time datetime="2013-02-20T00:00:00+00:00">February 20, 2013 00:00</time>'
assert_equal expected, time_tag(time)
end
@ -3184,8 +3184,8 @@ class DateHelperTest < ActionView::TestCase
end
def test_time_tag_with_different_format
time = Time.now
expected = "<time datetime=\"#{time.xmlschema}\">#{I18n.l(time, :format => :short)}</time>"
time = Time.new(2013, 2, 20, 0, 0, 0, '+00:00')
expected = '<time datetime="2013-02-20T00:00:00+00:00">20 Feb 00:00</time>'
assert_equal expected, time_tag(time, :format => :short)
end