From 9f1c37ecb367931f69908a7a3ad4bc062606406a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Poffo?= Date: Wed, 6 Feb 2019 17:24:20 -0200 Subject: [PATCH] Codeclimate - Complexity --- src/diagrams/gantt/ganttDb.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index d74eaf599..e8b812859 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -63,19 +63,17 @@ export const getTasks = function () { return tasks } +const isInvalidDate = function (date, dateFormat, excludes) { + if (date.isoWeekday() >= 6 && excludes.indexOf('weekends') >= 0) + return true; + return excludes.indexOf(date.format(dateFormat.trim())) >= 0; +} + const getNextValidDate = function (date, dateFormat, excludes) { - const excludeWeekends = excludes.indexOf('weekend') >= 0 || excludes.indexOf('weekends') >= 0 - const trimmedDateFormat = dateFormat.trim() - let mDate = moment.isMoment(date) ? date : (moment.isDate(date) ? moment(date) : moment(date, dateFormat, true)) - - const isInvalidDate = function (d) { - return (excludeWeekends && d.isoWeekday() >= 6) || (excludes.indexOf(d.format(trimmedDateFormat)) >= 0) - } - - while (isInvalidDate(mDate)) { + let mDate = moment(date, dateFormat, true) + while (isInvalidDate(mDate, dateFormat, excludes)) { mDate = mDate.add(1, 'd') } - return mDate.toDate() }