diff options
author | Go MAEDA <maeda@farend.jp> | 2025-01-30 22:11:19 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2025-01-30 22:11:19 +0000 |
commit | 09167d0b3238a4a7e27fded6a4111fe39f1bf22f (patch) | |
tree | e155ec0c5a8a70381377a0c6ba388d5fb78b221a | |
parent | c252857414ad6a665901eb76d6d32beac38da343 (diff) | |
download | redmine-09167d0b3238a4a7e27fded6a4111fe39f1bf22f.tar.gz redmine-09167d0b3238a4a7e27fded6a4111fe39f1bf22f.zip |
`format_hours` method produces incorrect output for negative time values when `Setting.timespan_format` is "minutes" (#42172).
Patch by Go MAEDA (user:maeda).
git-svn-id: https://svn.redmine.org/redmine/trunk@23482 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | lib/redmine/i18n.rb | 5 | ||||
-rw-r--r-- | test/helpers/application_helper_test.rb | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb index a9cd1dd0d..6d893ad22 100644 --- a/lib/redmine/i18n.rb +++ b/lib/redmine/i18n.rb @@ -94,8 +94,9 @@ module Redmine minutes = (hours * 60).round if Setting.timespan_format == 'minutes' - h, m = minutes.divmod(60) - "%d:%02d" % [h, m] + h, m = minutes.abs.divmod(60) + sign = minutes.negative? ? '-' : '' + "%s%d:%02d" % [sign, h, m] else number_with_delimiter(sprintf('%.2f', minutes.fdiv(60)), delimiter: nil) end diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 573eda42b..f959744e2 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -2210,11 +2210,15 @@ class ApplicationHelperTest < Redmine::HelperTest set_language_if_valid 'en' with_settings :timespan_format => 'minutes' do + assert_equal '-0:45', format_hours(-0.75) + assert_equal '0:00', format_hours(0) assert_equal '0:45', format_hours(0.75) assert_equal '0:45 h', l_hours_short(0.75) assert_equal '0:45 hour', l_hours(0.75) end with_settings :timespan_format => 'decimal' do + assert_equal '-0.75', format_hours(-0.75) + assert_equal '0.00', format_hours(0) assert_equal '0.75', format_hours(0.75) assert_equal '0.75 h', l_hours_short(0.75) assert_equal '0.75 hour', l_hours(0.75) |