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
Fix computing of days delta starting from a non-working day
Christophe Bliard67cd5757b459
diff --git a/app/services/work_packages/shared/working_days.rb b/app/services/work_packages/shared/working_days.rbindex e0a9372757d..031f5e60550 100644--- a/app/services/work_packages/shared/working_days.rb+++ b/app/services/work_packages/shared/working_days.rb@@ -83,13 +83,17 @@ module WorkPackagesenddef delta(previous:, current:)+ if current < previous+ return -delta(previous: current, current: previous)+ end+delta = 0- direction = previous < current ? 1 : -1- pos = last_pos = previous- while pos != current- pos += direction+ pos = last_pos = soonest_working_day(previous)++ while pos < current+ pos += 1if working?(last_pos) && working?(pos)- delta += direction+ delta += 1last_pos = posendenddiff --git a/spec/services/work_packages/shared/working_days_spec.rb b/spec/services/work_packages/shared/working_days_spec.rbindex c0d2ef0ebb7..aacad55a6ab 100644--- a/spec/services/work_packages/shared/working_days_spec.rb+++ b/spec/services/work_packages/shared/working_days_spec.rb@@ -276,8 +276,12 @@ RSpec.describe WorkPackages::Shared::WorkingDays docontext 'with weekend days (Saturday and Sunday)', :weekend_saturday_sunday doinclude_examples 'delta', previous: friday_2022_07_29, current: saturday_2022_07_30, expected: 0+ include_examples 'delta', previous: friday_2022_07_29, current: sunday_2022_07_31, expected: 0include_examples 'delta', previous: saturday_2022_07_30, current: monday_2022_08_01, expected: 0+ include_examples 'delta', previous: saturday_2022_07_30, current: sunday_2022_07_31, expected: 0include_examples 'delta', previous: sunday_2022_07_31, current: monday_2022_08_01, expected: 0+ include_examples 'delta', previous: saturday_2022_07_30, current: wednesday_2022_08_03, expected: 2+ include_examples 'delta', previous: sunday_2022_07_31, current: wednesday_2022_08_03, expected: 2include_examples 'delta', previous: friday_2022_07_29, current: monday_2022_08_01, expected: 1include_examples 'delta', previous: friday_2022_07_29, current: Date.new(2022, 8, 5), expected: 5include_examples 'delta', previous: friday_2022_07_29, current: Date.new(2022, 8, 8), expected: 6