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)
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?
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