Defect #36897 » 36897.patch
lib/redmine/i18n.rb | ||
---|---|---|
92 | 92 |
def format_hours(hours) |
93 | 93 |
return "" if hours.blank? |
94 | 94 | |
95 |
minutes = (hours * 60).round |
|
95 | 96 |
if Setting.timespan_format == 'minutes' |
96 |
h = hours.floor |
|
97 |
m = ((hours - h) * 60).round |
|
97 |
h, m = minutes.divmod(60) |
|
98 | 98 |
"%d:%02d" % [h, m] |
99 | 99 |
else |
100 |
number_with_delimiter(sprintf('%.2f', hours.to_f), delimiter: nil)
|
|
100 |
number_with_delimiter(sprintf('%.2f', minutes / 60.0), delimiter: nil)
|
|
101 | 101 |
end |
102 | 102 |
end |
103 | 103 |
test/helpers/application_helper_test.rb | ||
---|---|---|
2204 | 2204 |
end |
2205 | 2205 |
end |
2206 | 2206 | |
2207 |
def test_format_hours_rounds_to_nearest_minute |
|
2208 |
set_language_if_valid 'en' |
|
2209 | ||
2210 |
# 7h 59m 29s (7.991388888888889) -> 7h 59m (7.98) |
|
2211 |
# 7h 59m 30s (7.991666666666667) -> 8h 0m (8.00) |
|
2212 |
with_settings :timespan_format => 'minutes' do |
|
2213 |
assert_equal '7:59', format_hours(7.991388888888889) |
|
2214 |
assert_equal '8:00', format_hours(7.991666666666667) |
|
2215 |
end |
|
2216 |
with_settings :timespan_format => 'decimal' do |
|
2217 |
assert_equal '7.98', format_hours(7.991388888888889) |
|
2218 |
assert_equal '8.00', format_hours(7.991666666666667) |
|
2219 |
end |
|
2220 |
end |
|
2221 | ||
2207 | 2222 |
def test_format_hours_should_use_locale_decimal_separator |
2208 | 2223 |
to_test = {'en' => '0.75', 'de' => '0,75'} |
2209 | 2224 |
with_settings :timespan_format => 'decimal' do |
- « Previous
- 1
- …
- 4
- 5
- 6
- Next »