Display dates using user's locale if available (#2190).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9838 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Etienne Massip
2012-06-16 21:45:47 +00:00
parent 2c07b478bb
commit dbdc9b9da7
3 changed files with 38 additions and 7 deletions
+8 -3
View File
@@ -37,16 +37,21 @@ module Redmine
def format_date(date)
return nil unless date
Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format)
options = {}
options[:format] = Setting.date_format unless Setting.date_format.blank?
options[:locale] = User.current.language unless User.current.language.blank?
::I18n.l(date.to_date, options)
end
def format_time(time, include_date = true)
return nil unless time
options = {}
options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format)
options[:locale] = User.current.language unless User.current.language.blank?
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)
(include_date ? "#{format_date(local)} " : "") +
(Setting.time_format.blank? ? ::I18n.l(local, :format => :time) : local.strftime(Setting.time_format))
(include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options)
end
def day_name(day)