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

simplify data calculation on seeder

ulfertse9630be585bb
diff --git a/app/seeders/demo_data/work_package_seeder.rb b/app/seeders/demo_data/work_package_seeder.rb
index 74ed0940a6b..afc2c751a0d 100644
--- a/app/seeders/demo_data/work_package_seeder.rb
+++ b/app/seeders/demo_data/work_package_seeder.rb
@@ -148,7 +148,7 @@ module DemoData
end
def set_time_tracking_attributes!(wp_attr, attributes)
- start_date = attributes[:start] && calculate_start_date(attributes[:start])
+ start_date = calculate_start_date(attributes[:start])
wp_attr[:start_date] = start_date
wp_attr[:due_date] = calculate_due_date(start_date, attributes[:duration]) if start_date && attributes[:duration]
@@ -207,12 +207,13 @@ module DemoData
end
def calculate_start_date(days_ahead)
- monday = Date.today.monday
- days_ahead > 0 ? monday + days_ahead : monday
+ Time.zone.today.monday + (days_ahead || 0).days
end
+ # Returns the due date based on the starting date and the duration
+ # but ensures that the due date cannot be before the start date.
def calculate_due_date(date, duration)
- duration && duration > 1 ? date + duration : date
+ [date + ((duration || 0) - 1).days, date].max
end
end
end