Codeclimate - Complexity

This commit is contained in:
João Paulo Poffo
2019-02-06 17:24:20 -02:00
parent 8e8651a0e1
commit 9f1c37ecb3

View File

@@ -63,19 +63,17 @@ export const getTasks = function () {
return tasks return tasks
} }
const getNextValidDate = function (date, dateFormat, excludes) { const isInvalidDate = function (date, dateFormat, excludes) {
const excludeWeekends = excludes.indexOf('weekend') >= 0 || excludes.indexOf('weekends') >= 0 if (date.isoWeekday() >= 6 && excludes.indexOf('weekends') >= 0)
const trimmedDateFormat = dateFormat.trim() return true;
let mDate = moment.isMoment(date) ? date : (moment.isDate(date) ? moment(date) : moment(date, dateFormat, true)) return excludes.indexOf(date.format(dateFormat.trim())) >= 0;
const isInvalidDate = function (d) {
return (excludeWeekends && d.isoWeekday() >= 6) || (excludes.indexOf(d.format(trimmedDateFormat)) >= 0)
} }
while (isInvalidDate(mDate)) { const getNextValidDate = function (date, dateFormat, excludes) {
let mDate = moment(date, dateFormat, true)
while (isInvalidDate(mDate, dateFormat, excludes)) {
mDate = mDate.add(1, 'd') mDate = mDate.add(1, 'd')
} }
return mDate.toDate() return mDate.toDate()
} }