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
Use Days service to compute duration
Christophe Bliard1eb917a5bfaf
diff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rbindex 1635e5ed284..f57bc58700f 100644--- a/app/services/work_packages/set_schedule_service.rb+++ b/app/services/work_packages/set_schedule_service.rb@@ -184,11 +184,8 @@ class WorkPackages::SetScheduleServicedef set_dates(work_package, start_date, due_date)work_package.start_date = start_datework_package.due_date = due_date- work_package.duration = if start_date && due_date- due_date - start_date + 1- else- # This needs to change to nil once duration can be set- 1- end+ work_package.duration = WorkPackages::Shared::Days+ .for(work_package)+ .duration(start_date, due_date)endenddiff --git a/spec/factories/work_package_factory.rb b/spec/factories/work_package_factory.rbindex 3199f9ea8d0..3aefb0b94c2 100644--- a/spec/factories/work_package_factory.rb+++ b/spec/factories/work_package_factory.rb@@ -40,14 +40,7 @@ FactoryBot.define doauthor factory: :usercreated_at { Time.zone.now }updated_at { Time.zone.now }- duration do- if start_date && due_date- due_date - start_date + 1- else- # This needs to change to nil once duration can be set- 1- end- end+ duration { WorkPackages::Shared::AllDays.new.duration(start_date&.to_date, due_date&.to_date) }callback(:after_build) do |work_package, evaluator|work_package.type = work_package.project.types.first unless work_package.typediff --git a/spec/services/work_packages/set_schedule_service_spec.rb b/spec/services/work_packages/set_schedule_service_spec.rbindex 2128df5399e..112693167ed 100644--- a/spec/services/work_packages/set_schedule_service_spec.rb+++ b/spec/services/work_packages/set_schedule_service_spec.rb@@ -142,12 +142,7 @@ describe WorkPackages::SetScheduleService do.to eql(due_date),"Expected work package ##{wp.id} '#{wp.subject}' to have due date #{due_date}, got #{result.due_date}"- duration = if start_date && due_date- (due_date - start_date + 1).to_i- else- # This needs to change to nil once duration can be set- 1- end+ duration = WorkPackages::Shared::AllDays.new.duration(start_date, due_date)expect(result.duration).to eql(duration),