Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

use elegant code suggested in https://github.com/opf/openproject/pull/18583#discussion_r2046954108

as-op479ed6fbc4e2
diff --git a/lib/chronic_duration.rb b/lib/chronic_duration.rb
index 4c3f4a901d7..c2db4e9b479 100644
--- a/lib/chronic_duration.rb
+++ b/lib/chronic_duration.rb
@@ -197,13 +197,7 @@ module ChronicDuration
# Pad zeros on minutes
divider = ":"
result = str.split(divider).each_with_index.map do |n, index|
- if index > 0 && n.length == 1
- "0#{n}"
- elsif index > 0 && n.empty?
- "00"
- else
- n
- end
+ n.rjust(index > 0 ? 2 : 1, "0")
end.join(divider)
"#{result} h"
end