Fixed: date part of the time default format doesn't respect the date format (#7639).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4894 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-02-20 14:56:37 +00:00
parent 20a54f1ef5
commit 7ddb1c694a
2 changed files with 30 additions and 7 deletions

View File

@ -45,8 +45,8 @@ module Redmine
time = time.to_time if time.is_a?(String) time = time.to_time if time.is_a?(String)
zone = User.current.time_zone zone = User.current.time_zone
local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
Setting.time_format.blank? ? ::I18n.l(local, :format => (include_date ? :default : :time)) : (include_date ? "#{format_date(local)} " : "") +
((include_date ? "#{format_date(time)} " : "") + "#{local.strftime(Setting.time_format)}") (Setting.time_format.blank? ? ::I18n.l(local, :format => :time) : local.strftime(Setting.time_format))
end end
def day_name(day) def day_name(day)

View File

@ -58,13 +58,36 @@ class Redmine::I18nTest < ActiveSupport::TestCase
end end
end end
def test_time_format
set_language_if_valid 'en'
now = Time.parse('2011-02-20 15:45:22')
with_settings :time_format => '%H:%M' do
with_settings :date_format => '' do
assert_equal '02/20/2011 15:45', format_time(now)
assert_equal '15:45', format_time(now, false)
end
with_settings :date_format => '%Y-%m-%d' do
assert_equal '2011-02-20 15:45', format_time(now)
assert_equal '15:45', format_time(now, false)
end
end
end
def test_time_format_default def test_time_format_default
set_language_if_valid 'en' set_language_if_valid 'en'
now = Time.now now = Time.parse('2011-02-20 15:45:22')
Setting.date_format = '' with_settings :time_format => '' do
Setting.time_format = '' with_settings :date_format => '' do
assert_equal I18n.l(now), format_time(now) assert_equal '02/20/2011 03:45 pm', format_time(now)
assert_equal I18n.l(now, :format => :time), format_time(now, false) assert_equal '03:45 pm', format_time(now, false)
end
with_settings :date_format => '%Y-%m-%d' do
assert_equal '2011-02-20 03:45 pm', format_time(now)
assert_equal '03:45 pm', format_time(now, false)
end
end
end end
def test_time_format def test_time_format