Project

General

Profile

Defect #36897 » 36897.patch

Go MAEDA, 2024-07-22 06:03

View differences:

lib/redmine/i18n.rb
def format_hours(hours)
return "" if hours.blank?
minutes = (hours * 60).round
if Setting.timespan_format == 'minutes'
h = hours.floor
m = ((hours - h) * 60).round
h, m = minutes.divmod(60)
"%d:%02d" % [h, m]
else
number_with_delimiter(sprintf('%.2f', hours.to_f), delimiter: nil)
number_with_delimiter(sprintf('%.2f', minutes / 60.0), delimiter: nil)
end
end
test/helpers/application_helper_test.rb
end
end
def test_format_hours_rounds_to_nearest_minute
set_language_if_valid 'en'
# 7h 59m 29s (7.991388888888889) -> 7h 59m (7.98)
# 7h 59m 30s (7.991666666666667) -> 8h 0m (8.00)
with_settings :timespan_format => 'minutes' do
assert_equal '7:59', format_hours(7.991388888888889)
assert_equal '8:00', format_hours(7.991666666666667)
end
with_settings :timespan_format => 'decimal' do
assert_equal '7.98', format_hours(7.991388888888889)
assert_equal '8.00', format_hours(7.991666666666667)
end
end
def test_format_hours_should_use_locale_decimal_separator
to_test = {'en' => '0.75', 'de' => '0,75'}
with_settings :timespan_format => 'decimal' do
(6-6/6)