From 5495e6f3424f44faa16b4d03dfe1e76a30e50469 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 18 Nov 2016 12:42:20 +0000 Subject: Introduce a setting to change the display format of timespans to h:mm (#23996). Patch by Jens Kraemer. git-svn-id: http://svn.redmine.org/redmine/trunk@15965 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/i18n.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb index 7b4495e0e..dfeaf474e 100644 --- a/lib/redmine/i18n.rb +++ b/lib/redmine/i18n.rb @@ -45,11 +45,11 @@ module Redmine def l_hours(hours) hours = hours.to_f - l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f)) + l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => format_hours(hours)) end def l_hours_short(hours) - l(:label_f_hour_short, :value => ("%.2f" % hours.to_f)) + l(:label_f_hour_short, :value => format_hours(hours.to_f)) end def ll(lang, str, arg=nil) @@ -82,6 +82,18 @@ module Redmine (include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options) end + def format_hours(hours) + return "" if hours.blank? + + if Setting.timespan_format == 'minutes' + h = hours.floor + m = ((hours - h) * 60).round + "%d:%02d" % [ h, m ] + else + "%.2f" % hours.to_f + end + end + def day_name(day) ::I18n.t('date.day_names')[day % 7] end -- cgit v1.2.3