summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/redmine/i18n.rb4
-rw-r--r--test/unit/lib/redmine/i18n_test.rb33
2 files changed, 30 insertions, 7 deletions
diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb
index 1bfca81e4..f0cc529b0 100644
--- a/lib/redmine/i18n.rb
+++ b/lib/redmine/i18n.rb
@@ -45,8 +45,8 @@ module Redmine
time = time.to_time if time.is_a?(String)
zone = User.current.time_zone
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(time)} " : "") + "#{local.strftime(Setting.time_format)}")
+ (include_date ? "#{format_date(local)} " : "") +
+ (Setting.time_format.blank? ? ::I18n.l(local, :format => :time) : local.strftime(Setting.time_format))
end
def day_name(day)
diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb
index 5bb69c9a5..7ef5feb39 100644
--- a/test/unit/lib/redmine/i18n_test.rb
+++ b/test/unit/lib/redmine/i18n_test.rb
@@ -58,13 +58,36 @@ class Redmine::I18nTest < ActiveSupport::TestCase
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
set_language_if_valid 'en'
- now = Time.now
- Setting.date_format = ''
- Setting.time_format = ''
- assert_equal I18n.l(now), format_time(now)
- assert_equal I18n.l(now, :format => :time), format_time(now, false)
+ now = Time.parse('2011-02-20 15:45:22')
+ with_settings :time_format => '' do
+ with_settings :date_format => '' do
+ assert_equal '02/20/2011 03:45 pm', format_time(now)
+ 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
def test_time_format