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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Timestamp: extracting redundant code into method
Sebastian Fiedlschusterdebc37df078b
diff --git a/app/models/timestamp.rb b/app/models/timestamp.rbindex b5c37fc9589..7ce855c217f 100644--- a/app/models/timestamp.rb+++ b/app/models/timestamp.rb@@ -150,10 +150,10 @@ class Timestamp# map -1y to P-1Y, -1m to P-1M, -1w to P-1W, -1d to P-1D# map -1y1d to P-1Y-1Dsign = "-" if string.start_with? "-"- years = string.scan(/(\d+)y/).flatten.first- months = string.scan(/(\d+)m/).flatten.first- weeks = string.scan(/(\d+)w/).flatten.first- days = string.scan(/(\d+)d/).flatten.first+ years = scan_for_shortcut_value(string:, unit: "y")+ months = scan_for_shortcut_value(string:, unit: "m")+ weeks = scan_for_shortcut_value(string:, unit: "w")+ days = scan_for_shortcut_value(string:, unit: "d")if years || months || weeks || daysstring = "P" \"#{sign if years}#{years}#{'Y' if years}" \@@ -166,4 +166,9 @@ class Timestampend# rubocop:enable Metrics/AbcSize# rubocop:enable Metrics/PerceivedComplexity++ def self.scan_for_shortcut_value(string:, unit:)+ string.scan(/(\d+)#{unit}/).flatten.first+ end+end