1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-01 03:57:15 +00:00

Fix issue where minutes part of a time entry is displayed as 60 instead of being carried over (#36897).

Patch by Go MAEDA (user:maeda).


git-svn-id: https://svn.redmine.org/redmine/trunk@22946 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2024-08-08 04:24:44 +00:00
parent 2bc9048bb1
commit c96ef014dd
2 changed files with 18 additions and 3 deletions

View File

@ -92,12 +92,12 @@ module Redmine
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.fdiv(60)), delimiter: nil)
end
end

View File

@ -2204,6 +2204,21 @@ class ApplicationHelperTest < Redmine::HelperTest
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