From afeb3b53c98995ab9d83a2b16172c1f22982a406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Poffo?= Date: Tue, 12 Feb 2019 17:52:18 -0200 Subject: [PATCH] Simplified methods --- src/diagrams/gantt/ganttDb.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index 4b15dc4d0..0329ba9a9 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -75,17 +75,20 @@ const isInvalidDate = function (date, dateFormat, excludes) { const checkTaskDates = function (task, dateFormat, excludes) { if (!excludes.length || task.manualEndTime) return - fixTaskDates(task, dateFormat, excludes) + let startTime = moment(task.startTime, dateFormat, true) + startTime.add(1, 'd') + let endTime = moment(task.endTime, dateFormat, true) + let renderEndTime = fixTaskDates(startTime, endTime, dateFormat, excludes) + task.endTime = endTime.toDate() + task.renderEndTime = renderEndTime } -const fixTaskDates = function (task, dateFormat, excludes) { - let startTime = moment(task.startTime) - startTime.add(1, 'd') - let endTime = moment(task.endTime) +const fixTaskDates = function (startTime, endTime, dateFormat, excludes) { let invalid = false + let renderEndTime = null while (startTime.date() <= endTime.date()) { if (!invalid) { - task.renderEndTime = endTime.toDate() + renderEndTime = endTime.toDate() } invalid = isInvalidDate(startTime, dateFormat, excludes) if (invalid) { @@ -93,7 +96,7 @@ const fixTaskDates = function (task, dateFormat, excludes) { } startTime.add(1, 'd') } - task.endTime = endTime.toDate() + return renderEndTime } const getStartDate = function (prevTime, dateFormat, str) {