##// END OF EJS Templates
Template error when user's timezone isn't set and UTC timestamps are used (#1889)....
Jean-Philippe Lang -
r1799:8d6b32645c7b
parent child
Show More
@@ -95,7 +95,7 module ApplicationHelper
95 return nil unless time
95 return nil unless time
96 time = time.to_time if time.is_a?(String)
96 time = time.to_time if time.is_a?(String)
97 zone = User.current.time_zone
97 zone = User.current.time_zone
98 local = zone ? time.in_time_zone(zone) : (time.utc? ? time.utc_to_local : time)
98 local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
99 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
99 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
100 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
100 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
101 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
101 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
@@ -144,7 +144,7 class User < ActiveRecord::Base
144 end
144 end
145
145
146 def time_zone
146 def time_zone
147 self.pref.time_zone.nil? ? nil : TimeZone[self.pref.time_zone]
147 @time_zone ||= (self.pref.time_zone.blank? ? nil : TimeZone[self.pref.time_zone])
148 end
148 end
149
149
150 def wants_comments_in_reverse_order?
150 def wants_comments_in_reverse_order?
@@ -351,4 +351,12 EXPECTED
351 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
351 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
352 assert_equal now.strftime('%H %M'), format_time(now, false)
352 assert_equal now.strftime('%H %M'), format_time(now, false)
353 end
353 end
354
355 def test_utc_time_format
356 now = Time.now.utc
357 Setting.date_format = '%d %m %Y'
358 Setting.time_format = '%H %M'
359 assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now)
360 assert_equal Time.now.strftime('%H %M'), format_time(now, false)
361 end
354 end
362 end
General Comments 0
You need to be logged in to leave comments. Login now