From 7362e9b7efefab5c784f8a5917536035d71a26f8 Mon Sep 17 00:00:00 2001 From: Jan Schulz-Hofen Date: Fri, 11 Dec 2015 15:16:14 +0700 Subject: Add optional user parameter to I18n#format_time to override User.current This is useful for mails where times should be displayed in the timezone of the recipient - not the current user causing the mail to be sent. --- lib/redmine/i18n.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb index 9523f23..df6c136 100644 --- a/lib/redmine/i18n.rb +++ b/lib/redmine/i18n.rb @@ -71,12 +71,12 @@ module Redmine ::I18n.l(date.to_date, options) end - def format_time(time, include_date = true) + def format_time(time, include_date = true, user = nil) return nil unless time options = {} options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format) time = time.to_time if time.is_a?(String) - zone = User.current.time_zone + zone = (user || User.current).time_zone local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) (include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options) end -- 2.4.0