From: Jean-Philippe Lang Date: Thu, 11 Sep 2008 17:45:21 +0000 (+0000) Subject: Template error when user's timezone isn't set and UTC timestamps are used (#1889). X-Git-Tag: 0.8.0-RC1~254 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8d6b32645c7b3e928f01d3faf29e5e9fb1c89129;p=redmine.git Template error when user's timezone isn't set and UTC timestamps are used (#1889). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1801 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 78e5bdc65..cc26127d6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -95,7 +95,7 @@ module ApplicationHelper return nil unless time time = time.to_time if time.is_a?(String) zone = User.current.time_zone - local = zone ? time.in_time_zone(zone) : (time.utc? ? time.utc_to_local : time) + local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format) include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format) diff --git a/app/models/user.rb b/app/models/user.rb index 4f82f61b2..132896ad9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -144,7 +144,7 @@ class User < ActiveRecord::Base end def time_zone - self.pref.time_zone.nil? ? nil : TimeZone[self.pref.time_zone] + @time_zone ||= (self.pref.time_zone.blank? ? nil : TimeZone[self.pref.time_zone]) end def wants_comments_in_reverse_order? diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 452c0b535..6db029ada 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -351,4 +351,12 @@ EXPECTED assert_equal now.strftime('%d %m %Y %H %M'), format_time(now) assert_equal now.strftime('%H %M'), format_time(now, false) end + + def test_utc_time_format + now = Time.now.utc + Setting.date_format = '%d %m %Y' + Setting.time_format = '%H %M' + assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now) + assert_equal Time.now.strftime('%H %M'), format_time(now, false) + end end