From 1f5e1fddef5c5509608b0d5b1e1fee0527401749 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Thu, 27 Oct 2016 20:56:29 +0500 Subject: [PATCH 01/17] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 362 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 360 insertions(+), 2 deletions(-) diff --git a/robbery.js b/robbery.js index 4a8309d..0bc4170 100644 --- a/robbery.js +++ b/robbery.js @@ -4,7 +4,9 @@ * Сделано задание на звездочку * Реализовано оба метода и tryLater */ -exports.isStar = true; +exports.isStar = false; + +var DAYS_OF_WEEK = ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ', 'ВС']; /** * @param {Object} schedule – Расписание Банды @@ -16,6 +18,30 @@ exports.isStar = true; */ exports.getAppropriateMoment = function (schedule, duration, workingHours) { console.info(schedule, duration, workingHours); + var timePeriodsOfDays = [ + [ + { + from: parseTime(workingHours.from), + to: parseTime(workingHours.to), + countOfPeople: 0 + } + ], + [ + { + from: parseTime(workingHours.from), + to: parseTime(workingHours.to), + countOfPeople: 0 + } + ], + [ + { + from: parseTime(workingHours.from), + to: parseTime(workingHours.to), + countOfPeople: 0 + } + ] + ]; + return { @@ -24,6 +50,16 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { * @returns {Boolean} */ exists: function () { + if (checkParams(schedule, duration, workingHours)) { + return false; + } + convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours); + for (var i = 0; i < timePeriodsOfDays.length; i++) { + if (foundCorrectPeriod(timePeriodsOfDays[i], duration)) { + return true; + } + } + return false; }, @@ -35,7 +71,19 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { * @returns {String} */ format: function (template) { - return template; + if (checkParams(schedule, duration, workingHours)) { + return ''; + } + convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours); + for (var i = 0; i < timePeriodsOfDays.length; i++) { + timePeriodsOfDays[i].sort(sortPeriods); + template = createTemplate(template, timePeriodsOfDays[i], duration, i); + if (template.indexOf('%') === -1) { + return template; + } + } + + return ''; }, /** @@ -44,7 +92,317 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { * @returns {Boolean} */ tryLater: function () { + return false; } }; + }; + +function checkParams(schedule, duration, workingHours) { + return (schedule === null || duration === undefined || workingHours === null || + schedule === undefined || workingHours === undefined); +} + +function convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours) { + var parsedSchedule = { + Danny: [], + Rusty: [], + Linus: [] + }; + convertTimePeriods(schedule, parsedSchedule, workingHours); + var freeTimeSchedule = { + Danny: [], + Rusty: [], + Linus: [] + }; + inverseTimePeriods(parsedSchedule, freeTimeSchedule); + segmentsIntersection(freeTimeSchedule, timePeriodsOfDays); +} + +function convertTimePeriods(schedule, parsedSchedule, workingHours) { + var bankGMT = getBankGMT(workingHours); + for (var ind in schedule) { + if (schedule.hasOwnProperty(ind)) { + parseOnePersonPeriods(schedule[ind], parsedSchedule[ind], bankGMT); + } + } +} + +function getBankGMT(workingHours) { + var bankWorkGMT = 0; + if (workingHours.from.length > 5) { + bankWorkGMT = parseInt(workingHours.from.substr(6)); + } + + return bankWorkGMT; +} + +function parseOnePersonPeriods(person, parsedSchedulePerson, bankGMT) { + for (var j = 0; j < person.length; j++) { + var tryParseDataFrom = parseDataSchedule(person[j].from, bankGMT); + var tryParseDataTo = parseDataSchedule(person[j].to, bankGMT); + if (tryParseDataFrom.day > -1 && tryParseDataTo.day > -1) { + addNewParsedPeriod(parsedSchedulePerson, tryParseDataFrom, tryParseDataTo); + } + } +} + +function parseDataSchedule(item, gmtBank) { + var dayTime = { + day: -1, + time: new Date(2016, 0, 1) + }; + dayTime.day = DAYS_OF_WEEK.indexOf(item.substr(0, 2)); + if (dayTime.day !== -1) { + dayTime.time = parseTime(item.substr(3, 5)); + var gmtDate = parseInt(item.substr(9)); + setGTMBank(dayTime, gmtBank - gmtDate); + } + + return dayTime; +} + + +function parseTime(time) { + return parseInt(time.split(':')[0]) * 60 + parseInt(time.split(':')[1]); +} + +function setGTMBank(timeFree, gmtBankMove) { + timeFree.time = (timeFree.time + gmtBankMove * 60) % 1440; + if (timeFree.time < 0) { + timeFree.time += 1439; + if (timeFree.day === 0) { + timeFree.day = 6; + } else { + timeFree.day --; + } + } + if (Math.floor(timeFree.time / 1440) > 0) { + if (timeFree.day === 6) { + timeFree.day = 0; + } else { + timeFree.day ++; + } + } +} + +function addNewParsedPeriod(parsedSchedulePerson, tryParseDataFrom, tryParseDataTo) { + parsedSchedulePerson.push( + { + from: { + day: -1, + time: 0 + }, + to: { + day: -1, + time: 0 + } + } + ); + if (tryParseDataFrom.day === tryParseDataTo.day) { + assignment(tryParseDataFrom, + parsedSchedulePerson[parsedSchedulePerson.length - 1].from); + assignment(tryParseDataTo, + parsedSchedulePerson[parsedSchedulePerson.length - 1].to); + } else { + assignment(tryParseDataFrom, + parsedSchedulePerson[parsedSchedulePerson.length - 1].from); + parsedSchedulePerson[parsedSchedulePerson.length - 1].to.day = + tryParseDataFrom.day; + parsedSchedulePerson[parsedSchedulePerson.length - 1].to.time = + 1439; + parsedSchedulePerson.push( + { + from: { + day: -1, + time: 0 + }, + to: { + day: -1, + time: 0 + } + } + ); + parsedSchedulePerson[parsedSchedulePerson.length - 1].from.day = + tryParseDataTo.day; + parsedSchedulePerson[parsedSchedulePerson.length - 1].from.time = + 0; + assignment(tryParseDataTo, + parsedSchedulePerson[parsedSchedulePerson.length - 1].to); + } + +} + +function assignment(assignFrom, assignTo) { + assignTo.day = assignFrom.day; + assignTo.time = assignFrom.time; +} + +function inverseTimePeriods(parsedSchedule, freeTimeSchedule) { + for (var index in parsedSchedule) { + if (parsedSchedule.hasOwnProperty(index)) { + var listOfPeriodEnds = [[], [], []]; + createListOfPeriodEnds(parsedSchedule[index], listOfPeriodEnds); + listOfPeriodEnds.forEach(removeOrAddDayEnds); + createFreeTimePeriods(index, listOfPeriodEnds, freeTimeSchedule); + } + } + +} + +function createListOfPeriodEnds(item, listOfEnds) { + for (var j = 0; j < item.length; j++) { + var day = item[j].from.day; + if (day >= 0 && day <= 2) { + listOfEnds[day].push(item[j].from.time); + listOfEnds[day].push(item[j].to.time); + } + } +} + +function removeOrAddDayEnds(index) { + if (index.indexOf(0) > -1) { + index.splice(index.indexOf(0), 1); + } else { + index.push(0); + } + if (index.indexOf(1439) > -1) { + index.splice(index.indexOf(1439), 1); + } else { + index.push(1439); + } + index.sort(compareNumbers); +} + +function compareNumbers(a, b) { + if (a > b) { + return 1; + } + if (b > a) { + return -1; + } +} + +function createFreeTimePeriods(index, listOfPeriods, freeTimeSchedule) { + for (var k = 0; k < listOfPeriods.length; k++) { + for (var l = 0; l < listOfPeriods[k].length; l += 2) { + freeTimeSchedule[index].push( + { + from: 0, + to: 0, + day: -1 + } + ); + var lastElement = freeTimeSchedule[index].length - 1; + freeTimeSchedule[index][lastElement].day = k; + freeTimeSchedule[index][lastElement].from = listOfPeriods[k][l]; + freeTimeSchedule[index][lastElement].to = listOfPeriods[k][l + 1]; + } + } +} + +function segmentsIntersection(freeTime, timePeriodsOfDays) { + var countOfCycle = 0; + for (var person in freeTime) { + if (freeTime.hasOwnProperty(person)) { + countOfCycle = + createActualFreePeriods(freeTime[person], countOfCycle, timePeriodsOfDays); + } + } + +} + +function createActualFreePeriods(freeTime, countOfCycle, timePeriodsOfDays) { + for (var l = 0; l < freeTime.length; l++) { + createNewPeriod(freeTime[l], timePeriodsOfDays, countOfCycle); + } + countOfCycle ++; + clearWrongPeriods(timePeriodsOfDays, countOfCycle); + + return countOfCycle; +} + +function createNewPeriod(freeTimePeriod, timePeriodsOfDays, countOfCycle) { + var dayOfSchedule = freeTimePeriod.day; + for (var m = 0; m < timePeriodsOfDays[dayOfSchedule].length; m++) { + if ((freeTimePeriod.from > timePeriodsOfDays[dayOfSchedule][m].from && + freeTimePeriod.from < timePeriodsOfDays[dayOfSchedule][m].to || + freeTimePeriod.to < timePeriodsOfDays[dayOfSchedule][m].to && + freeTimePeriod.to > timePeriodsOfDays[dayOfSchedule][m].from + ) && timePeriodsOfDays[dayOfSchedule][m].countOfPeople === countOfCycle) { + timePeriodsOfDays[dayOfSchedule].push( + { + from: 0, + to: 0, + countOfPeople: 0 + } + ); + var lastElement = timePeriodsOfDays[dayOfSchedule].length - 1; + timePeriodsOfDays[dayOfSchedule][lastElement].from = + Math.max(freeTimePeriod.from, + timePeriodsOfDays[dayOfSchedule][m].from); + timePeriodsOfDays[dayOfSchedule][lastElement].to = + Math.min(freeTimePeriod.to, + timePeriodsOfDays[dayOfSchedule][m].to); + timePeriodsOfDays[dayOfSchedule][lastElement].countOfPeople = + countOfCycle + 1; + } + if (freeTimePeriod.from <= timePeriodsOfDays[dayOfSchedule][m].from && + freeTimePeriod.to >= timePeriodsOfDays[dayOfSchedule][m].to) { + timePeriodsOfDays[dayOfSchedule][m].countOfPeople = countOfCycle + 1; + } + } +} + +function clearWrongPeriods(timePeriods, countOfCycle) { + for (var o = 0; o < timePeriods.length; o++) { + deleteWrongPeriods(timePeriods[o], countOfCycle); + } +} + +function deleteWrongPeriods(timePeriods, countOfCycle) { + var n = 0; + while (n < timePeriods.length) { + if (timePeriods[n].countOfPeople < countOfCycle) { + timePeriods.splice(n, 1); + } else { + n++; + } + } +} + +function foundCorrectPeriod(timePeriodsOfDays, duration) { + for (var j = 0; j < timePeriodsOfDays.length; j++) { + if (timePeriodsOfDays[j].to - timePeriodsOfDays[j].from >= duration) { + return true; + } + } + + return false; +} + + +function sortPeriods(period1, period2) { + if (period1.from > period2.from) { + return 1; + } + if (period1.from < period2.from) { + return -1; + } +} + +function createTemplate(template, timePeriodsOfDay, duration, dayOfWeek) { + for (var j = 0; j < timePeriodsOfDay.length; j++) { + if (timePeriodsOfDay[j].to - timePeriodsOfDay[j].from >= duration) { + template = template.replace('%DD', DAYS_OF_WEEK[dayOfWeek]); + template = template.replace('%HH', + Math.floor(timePeriodsOfDay[j].from / 60)); + template = template.replace('%MM', timePeriodsOfDay[j].from % 60); + + return template; + } + } + + return template; +} From 802cefede3195ca1a3464fd23a849816ca74cc63 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Thu, 27 Oct 2016 21:56:07 +0500 Subject: [PATCH 02/17] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B2=D1=85=D0=BE=D0=B4=D0=BD=D1=8B=D1=85=20=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/robbery.js b/robbery.js index 0bc4170..9dd003a 100644 --- a/robbery.js +++ b/robbery.js @@ -50,7 +50,7 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { * @returns {Boolean} */ exists: function () { - if (checkParams(schedule, duration, workingHours)) { + if (checkBadParams(schedule, duration, workingHours)) { return false; } convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours); @@ -71,7 +71,7 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { * @returns {String} */ format: function (template) { - if (checkParams(schedule, duration, workingHours)) { + if (checkBadParams(schedule, duration, workingHours)) { return ''; } convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours); @@ -99,9 +99,34 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { }; -function checkParams(schedule, duration, workingHours) { - return (schedule === null || duration === undefined || workingHours === null || - schedule === undefined || workingHours === undefined); +function checkBadParams(schedule, duration, workingHours) { + return checkSchedule(schedule) || checkDuration(duration) || checkWorkingHours(workingHours); +} + +function checkSchedule(schedule) { + if (schedule === null || schedule === undefined || Object.keys(schedule).length !== 3 || + checkSchedulePerson(schedule)) { + return true; + } +} +function checkSchedulePerson(schedule) { + return (Object.keys(schedule).indexOf('Danny') === -1 || + Object.keys(schedule).indexOf('Rusty') === -1 || + Object.keys(schedule).indexOf('Linus') === -1); +} + +function checkDuration(duration) { + if (duration === undefined || Number.isNaN(duration) || duration < 0) { + return true; + } +} + +function checkWorkingHours(workingHours) { + if (workingHours === undefined || workingHours === null || + Object.keys(workingHours).indexOf('from') === - 1 || + Object.keys(workingHours).indexOf('to') === -1) { + return true; + } } function convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours) { @@ -151,7 +176,7 @@ function parseOnePersonPeriods(person, parsedSchedulePerson, bankGMT) { function parseDataSchedule(item, gmtBank) { var dayTime = { day: -1, - time: new Date(2016, 0, 1) + time: 0 }; dayTime.day = DAYS_OF_WEEK.indexOf(item.substr(0, 2)); if (dayTime.day !== -1) { From acbe1937d829f731ef3a8b81a072d147aad51753 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Thu, 27 Oct 2016 22:03:57 +0500 Subject: [PATCH 03/17] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D1=87=D0=B8=D1=81=D0=BB=D0=B0=20=D0=B2=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/robbery.js b/robbery.js index 9dd003a..ec4df3b 100644 --- a/robbery.js +++ b/robbery.js @@ -422,8 +422,9 @@ function createTemplate(template, timePeriodsOfDay, duration, dayOfWeek) { if (timePeriodsOfDay[j].to - timePeriodsOfDay[j].from >= duration) { template = template.replace('%DD', DAYS_OF_WEEK[dayOfWeek]); template = template.replace('%HH', - Math.floor(timePeriodsOfDay[j].from / 60)); - template = template.replace('%MM', timePeriodsOfDay[j].from % 60); + reportNumberToString(Math.floor(timePeriodsOfDay[j].from / 60))); + template = template.replace('%MM', + reportNumberToString(timePeriodsOfDay[j].from % 60)); return template; } @@ -431,3 +432,11 @@ function createTemplate(template, timePeriodsOfDay, duration, dayOfWeek) { return template; } + +function reportNumberToString(number) { + if (number < 10) { + return '0' + number; + } + + return number; +} From 23ac0c81a9e85c5fc11e64ef552d079695a3d323 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Thu, 27 Oct 2016 22:17:33 +0500 Subject: [PATCH 04/17] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B2=D1=85=D0=BE=D0=B4=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/robbery.js b/robbery.js index ec4df3b..86b9aad 100644 --- a/robbery.js +++ b/robbery.js @@ -53,7 +53,9 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return false; } - convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours); + if(!convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours)) { + return false; + } for (var i = 0; i < timePeriodsOfDays.length; i++) { if (foundCorrectPeriod(timePeriodsOfDays[i], duration)) { return true; @@ -74,7 +76,9 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return ''; } - convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours); + if(!convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours)) { + return ''; + } for (var i = 0; i < timePeriodsOfDays.length; i++) { timePeriodsOfDays[i].sort(sortPeriods); template = createTemplate(template, timePeriodsOfDays[i], duration, i); @@ -135,7 +139,9 @@ function convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours) { Rusty: [], Linus: [] }; - convertTimePeriods(schedule, parsedSchedule, workingHours); + if (!convertTimePeriods(schedule, parsedSchedule, workingHours)) { + return false; + } var freeTimeSchedule = { Danny: [], Rusty: [], @@ -143,15 +149,19 @@ function convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours) { }; inverseTimePeriods(parsedSchedule, freeTimeSchedule); segmentsIntersection(freeTimeSchedule, timePeriodsOfDays); + return true; } function convertTimePeriods(schedule, parsedSchedule, workingHours) { var bankGMT = getBankGMT(workingHours); for (var ind in schedule) { if (schedule.hasOwnProperty(ind)) { - parseOnePersonPeriods(schedule[ind], parsedSchedule[ind], bankGMT); + if (!parseOnePersonPeriods(schedule[ind], parsedSchedule[ind], bankGMT)) { + return false; + } } } + return true; } function getBankGMT(workingHours) { @@ -170,7 +180,12 @@ function parseOnePersonPeriods(person, parsedSchedulePerson, bankGMT) { if (tryParseDataFrom.day > -1 && tryParseDataTo.day > -1) { addNewParsedPeriod(parsedSchedulePerson, tryParseDataFrom, tryParseDataTo); } + else { + return false; + } } + + return true; } function parseDataSchedule(item, gmtBank) { From 0e7f4d5de20a43c0d957745fe44ba6c6f333eb12 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Thu, 27 Oct 2016 23:18:07 +0500 Subject: [PATCH 05/17] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BB=D0=B8=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/robbery.js b/robbery.js index 86b9aad..030be14 100644 --- a/robbery.js +++ b/robbery.js @@ -53,7 +53,7 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return false; } - if(!convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours)) { + if (!convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours)) { return false; } for (var i = 0; i < timePeriodsOfDays.length; i++) { @@ -76,7 +76,7 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return ''; } - if(!convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours)) { + if (!convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours)) { return ''; } for (var i = 0; i < timePeriodsOfDays.length; i++) { @@ -149,18 +149,19 @@ function convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours) { }; inverseTimePeriods(parsedSchedule, freeTimeSchedule); segmentsIntersection(freeTimeSchedule, timePeriodsOfDays); + return true; } function convertTimePeriods(schedule, parsedSchedule, workingHours) { var bankGMT = getBankGMT(workingHours); for (var ind in schedule) { - if (schedule.hasOwnProperty(ind)) { - if (!parseOnePersonPeriods(schedule[ind], parsedSchedule[ind], bankGMT)) { - return false; - } + if (!schedule.hasOwnProperty(ind) || + !parseOnePersonPeriods(schedule[ind], parsedSchedule[ind], bankGMT)) { + return false; } } + return true; } @@ -179,8 +180,7 @@ function parseOnePersonPeriods(person, parsedSchedulePerson, bankGMT) { var tryParseDataTo = parseDataSchedule(person[j].to, bankGMT); if (tryParseDataFrom.day > -1 && tryParseDataTo.day > -1) { addNewParsedPeriod(parsedSchedulePerson, tryParseDataFrom, tryParseDataTo); - } - else { + } else { return false; } } @@ -193,6 +193,7 @@ function parseDataSchedule(item, gmtBank) { day: -1, time: 0 }; + dayTime.day = DAYS_OF_WEEK.indexOf(item.substr(0, 2)); if (dayTime.day !== -1) { dayTime.time = parseTime(item.substr(3, 5)); From a062d25c10305d512cb0b847edc63d1871c44e35 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 19:48:19 +0500 Subject: [PATCH 06/17] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/robbery.js b/robbery.js index 030be14..043e3f5 100644 --- a/robbery.js +++ b/robbery.js @@ -108,29 +108,18 @@ function checkBadParams(schedule, duration, workingHours) { } function checkSchedule(schedule) { - if (schedule === null || schedule === undefined || Object.keys(schedule).length !== 3 || - checkSchedulePerson(schedule)) { - return true; - } -} -function checkSchedulePerson(schedule) { - return (Object.keys(schedule).indexOf('Danny') === -1 || - Object.keys(schedule).indexOf('Rusty') === -1 || - Object.keys(schedule).indexOf('Linus') === -1); + return (schedule === null || schedule === undefined); } function checkDuration(duration) { - if (duration === undefined || Number.isNaN(duration) || duration < 0) { - return true; - } + return (duration === undefined || Number.isNaN(duration) || duration < 0); } function checkWorkingHours(workingHours) { - if (workingHours === undefined || workingHours === null || - Object.keys(workingHours).indexOf('from') === - 1 || - Object.keys(workingHours).indexOf('to') === -1) { - return true; - } + return (workingHours === undefined || workingHours === null || + Object.keys(workingHours).indexOf('from') === -1 || + Object.keys(workingHours).indexOf('to') === -1); + } function convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours) { @@ -193,7 +182,10 @@ function parseDataSchedule(item, gmtBank) { day: -1, time: 0 }; - + if (item.search(/^[А-Я]{2}\s\d{2}:\d{2}\+\d\d?$/) === -1 || item.length < 10 || + item.length > 11) { + return dayTime; + } dayTime.day = DAYS_OF_WEEK.indexOf(item.substr(0, 2)); if (dayTime.day !== -1) { dayTime.time = parseTime(item.substr(3, 5)); From 0fc9b82d03af915e9fae44009a3a4275b64cb952 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 20:07:46 +0500 Subject: [PATCH 07/17] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=BD=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/robbery.js b/robbery.js index 043e3f5..d99577b 100644 --- a/robbery.js +++ b/robbery.js @@ -118,10 +118,24 @@ function checkDuration(duration) { function checkWorkingHours(workingHours) { return (workingHours === undefined || workingHours === null || Object.keys(workingHours).indexOf('from') === -1 || - Object.keys(workingHours).indexOf('to') === -1); + Object.keys(workingHours).indexOf('to') === -1 || + checkBankTimeStrings(workingHours)); } +function checkBankTimeStrings(workingHours) { + var isNotCorrectString = false; + for (var index in workingHours) { + if (workingHours.hasOwnProperty(index)) { + isNotCorrectString = isNotCorrectString || + workingHours[index].search(/^\d{2}:\d{2}\+\d\d?/) === -1 || + workingHours[index].length < 7 || workingHours[index].length > 8; + } + } + + return isNotCorrectString; +} + function convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours) { var parsedSchedule = { Danny: [], From 3dd0359c53d2dd08790e7490d400eab4b564e485 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 20:15:14 +0500 Subject: [PATCH 08/17] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B2?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/robbery.js b/robbery.js index d99577b..732bcb1 100644 --- a/robbery.js +++ b/robbery.js @@ -112,7 +112,8 @@ function checkSchedule(schedule) { } function checkDuration(duration) { - return (duration === undefined || Number.isNaN(duration) || duration < 0); + return (duration === undefined || Number.isNaN(duration) || + duration <= 0 || duration === null); } function checkWorkingHours(workingHours) { From 3170f8716d7678b562a92e6a8e9bf21c7eae91fd Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 20:40:14 +0500 Subject: [PATCH 09/17] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BF=D0=BE=D1=8F=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/robbery.js b/robbery.js index 732bcb1..5303ff6 100644 --- a/robbery.js +++ b/robbery.js @@ -129,7 +129,7 @@ function checkBankTimeStrings(workingHours) { for (var index in workingHours) { if (workingHours.hasOwnProperty(index)) { isNotCorrectString = isNotCorrectString || - workingHours[index].search(/^\d{2}:\d{2}\+\d\d?/) === -1 || + workingHours[index].search(/^\d{2}:\d{2}\+[1-9]\d?/) === -1 || workingHours[index].length < 7 || workingHours[index].length > 8; } } @@ -158,7 +158,7 @@ function convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours) { } function convertTimePeriods(schedule, parsedSchedule, workingHours) { - var bankGMT = getBankGMT(workingHours); + var bankGMT = parseInt(workingHours.from.substr(6)); for (var ind in schedule) { if (!schedule.hasOwnProperty(ind) || !parseOnePersonPeriods(schedule[ind], parsedSchedule[ind], bankGMT)) { @@ -169,15 +169,6 @@ function convertTimePeriods(schedule, parsedSchedule, workingHours) { return true; } -function getBankGMT(workingHours) { - var bankWorkGMT = 0; - if (workingHours.from.length > 5) { - bankWorkGMT = parseInt(workingHours.from.substr(6)); - } - - return bankWorkGMT; -} - function parseOnePersonPeriods(person, parsedSchedulePerson, bankGMT) { for (var j = 0; j < person.length; j++) { var tryParseDataFrom = parseDataSchedule(person[j].from, bankGMT); @@ -197,7 +188,7 @@ function parseDataSchedule(item, gmtBank) { day: -1, time: 0 }; - if (item.search(/^[А-Я]{2}\s\d{2}:\d{2}\+\d\d?$/) === -1 || item.length < 10 || + if (item.search(/^[А-Я]{2}\s\d{2}:\d{2}\+[1-9]\d?$/) === -1 || item.length < 10 || item.length > 11) { return dayTime; } From 5f0c2ce76cf20758da03f0b5d9576c0d6ec581dd Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 20:56:29 +0500 Subject: [PATCH 10/17] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=81=20=D0=BF=D0=B5=D1=80=D0=B8=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/robbery.js b/robbery.js index 5303ff6..d684cd6 100644 --- a/robbery.js +++ b/robbery.js @@ -18,30 +18,6 @@ var DAYS_OF_WEEK = ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ', 'ВС']; */ exports.getAppropriateMoment = function (schedule, duration, workingHours) { console.info(schedule, duration, workingHours); - var timePeriodsOfDays = [ - [ - { - from: parseTime(workingHours.from), - to: parseTime(workingHours.to), - countOfPeople: 0 - } - ], - [ - { - from: parseTime(workingHours.from), - to: parseTime(workingHours.to), - countOfPeople: 0 - } - ], - [ - { - from: parseTime(workingHours.from), - to: parseTime(workingHours.to), - countOfPeople: 0 - } - ] - ]; - return { @@ -53,9 +29,22 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return false; } + + var timePeriodsOfDays = [[], [], []]; + for (var j = 0; j < timePeriodsOfDays.length; j++) { + timePeriodsOfDays[j].push( + { + from: parseTime(workingHours.from), + to: parseTime(workingHours.to), + countOfPeople: 0 + } + ); + } + if (!convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours)) { return false; } + for (var i = 0; i < timePeriodsOfDays.length; i++) { if (foundCorrectPeriod(timePeriodsOfDays[i], duration)) { return true; @@ -76,6 +65,16 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return ''; } + var timePeriodsOfDays = [[], [], []]; + for (var j = 0; j < timePeriodsOfDays.length; j++) { + timePeriodsOfDays[j].push( + { + from: parseTime(workingHours.from), + to: parseTime(workingHours.to), + countOfPeople: 0 + } + ); + } if (!convertDataToFreePeriods(schedule, timePeriodsOfDays, workingHours)) { return ''; } @@ -129,7 +128,7 @@ function checkBankTimeStrings(workingHours) { for (var index in workingHours) { if (workingHours.hasOwnProperty(index)) { isNotCorrectString = isNotCorrectString || - workingHours[index].search(/^\d{2}:\d{2}\+[1-9]\d?/) === -1 || + workingHours[index].search(/^\d{2}:\d{2}\+[1-9]\d?$/) === -1 || workingHours[index].length < 7 || workingHours[index].length > 8; } } From 0df5c24b5628946c10cc9284071804f9eda94c97 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 20:59:50 +0500 Subject: [PATCH 11/17] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robbery.js b/robbery.js index d684cd6..111e1c1 100644 --- a/robbery.js +++ b/robbery.js @@ -112,7 +112,7 @@ function checkSchedule(schedule) { function checkDuration(duration) { return (duration === undefined || Number.isNaN(duration) || - duration <= 0 || duration === null); + duration <= 0 || duration === null || duration > 1439); } function checkWorkingHours(workingHours) { From 6d6b9272a16903123a668163b5323ba25140e140 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 21:04:28 +0500 Subject: [PATCH 12/17] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=B5=D0=BD=D0=B8=D0=B52?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/robbery.js b/robbery.js index 111e1c1..1261572 100644 --- a/robbery.js +++ b/robbery.js @@ -29,7 +29,9 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return false; } - + if (duration > parseTime(workingHours.to) - parseTime(workingHours.from)){ + return false; + } var timePeriodsOfDays = [[], [], []]; for (var j = 0; j < timePeriodsOfDays.length; j++) { timePeriodsOfDays[j].push( @@ -65,6 +67,9 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return ''; } + if (duration > parseTime(workingHours.to) - parseTime(workingHours.from)){ + return ''; + } var timePeriodsOfDays = [[], [], []]; for (var j = 0; j < timePeriodsOfDays.length; j++) { timePeriodsOfDays[j].push( @@ -112,7 +117,7 @@ function checkSchedule(schedule) { function checkDuration(duration) { return (duration === undefined || Number.isNaN(duration) || - duration <= 0 || duration === null || duration > 1439); + duration <= 0 || duration === null); } function checkWorkingHours(workingHours) { From 3805d0ddda9fc1b212242c873a701c8be6a4befc Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 21:07:18 +0500 Subject: [PATCH 13/17] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BB=D0=B8=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/robbery.js b/robbery.js index 1261572..986fa2b 100644 --- a/robbery.js +++ b/robbery.js @@ -29,9 +29,6 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return false; } - if (duration > parseTime(workingHours.to) - parseTime(workingHours.from)){ - return false; - } var timePeriodsOfDays = [[], [], []]; for (var j = 0; j < timePeriodsOfDays.length; j++) { timePeriodsOfDays[j].push( @@ -67,9 +64,6 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { if (checkBadParams(schedule, duration, workingHours)) { return ''; } - if (duration > parseTime(workingHours.to) - parseTime(workingHours.from)){ - return ''; - } var timePeriodsOfDays = [[], [], []]; for (var j = 0; j < timePeriodsOfDays.length; j++) { timePeriodsOfDays[j].push( @@ -108,7 +102,9 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { }; function checkBadParams(schedule, duration, workingHours) { - return checkSchedule(schedule) || checkDuration(duration) || checkWorkingHours(workingHours); + return (checkSchedule(schedule) || checkDuration(duration) || + checkWorkingHours(workingHours) || + duration > parseTime(workingHours.to) - parseTime(workingHours.from)); } function checkSchedule(schedule) { From 5f8be93339183aa07ec0e7440c8ded67fadf4516 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 21:57:11 +0500 Subject: [PATCH 14/17] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B8=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BD=D1=8F=D1=82=D0=BE=D1=81=D1=82=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B4=D0=BD?= =?UTF-8?q?=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/robbery.js b/robbery.js index 986fa2b..c2922fa 100644 --- a/robbery.js +++ b/robbery.js @@ -245,12 +245,16 @@ function addNewParsedPeriod(parsedSchedulePerson, tryParseDataFrom, tryParseData assignment(tryParseDataTo, parsedSchedulePerson[parsedSchedulePerson.length - 1].to); } else { + assignment(tryParseDataFrom, parsedSchedulePerson[parsedSchedulePerson.length - 1].from); parsedSchedulePerson[parsedSchedulePerson.length - 1].to.day = tryParseDataFrom.day; parsedSchedulePerson[parsedSchedulePerson.length - 1].to.time = 1439; + if (Math.abs(tryParseDataFrom.day - tryParseDataTo.day) > 1) { + addBusyDays(parsedSchedulePerson, tryParseDataFrom.day, tryParseDataTo.day); + } parsedSchedulePerson.push( { from: { @@ -278,6 +282,31 @@ function assignment(assignFrom, assignTo) { assignTo.time = assignFrom.time; } +function addBusyDays(parsedSchedulePerson, dayFrom, dayTo) { + var i = 0; + while ((dayFrom + i) % 7 !== dayTo) { + parsedSchedulePerson.push( + { + from: { + day: -1, + time: 0 + }, + to: { + day: -1, + time: 0 + } + } + ); + parsedSchedulePerson[parsedSchedulePerson.length - 1].from.day = + (dayFrom + i) % 7; + parsedSchedulePerson[parsedSchedulePerson.length - 1].from.time = 0; + parsedSchedulePerson[parsedSchedulePerson.length - 1].to.day = + (dayFrom + i) % 7; + parsedSchedulePerson[parsedSchedulePerson.length - 1].to.time = 1439; + i++; + } +} + function inverseTimePeriods(parsedSchedule, freeTimeSchedule) { for (var index in parsedSchedule) { if (parsedSchedule.hasOwnProperty(index)) { From 73cc46dc33bcad25194a4f1db0221bfb764a26ea Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 23:37:41 +0500 Subject: [PATCH 15/17] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=80=D0=B5=D0=B3=D0=B2=D1=8B=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/robbery.js b/robbery.js index c2922fa..02b280c 100644 --- a/robbery.js +++ b/robbery.js @@ -129,7 +129,7 @@ function checkBankTimeStrings(workingHours) { for (var index in workingHours) { if (workingHours.hasOwnProperty(index)) { isNotCorrectString = isNotCorrectString || - workingHours[index].search(/^\d{2}:\d{2}\+[1-9]\d?$/) === -1 || + workingHours[index].search(/^\d{2}:\d{2}\+[1-9]$/) === -1 || workingHours[index].length < 7 || workingHours[index].length > 8; } } @@ -188,7 +188,7 @@ function parseDataSchedule(item, gmtBank) { day: -1, time: 0 }; - if (item.search(/^[А-Я]{2}\s\d{2}:\d{2}\+[1-9]\d?$/) === -1 || item.length < 10 || + if (item.search(/^[А-Я]{2}\s\d{2}:\d{2}\+[1-9]$/) === -1 || item.length < 10 || item.length > 11) { return dayTime; } @@ -252,9 +252,6 @@ function addNewParsedPeriod(parsedSchedulePerson, tryParseDataFrom, tryParseData tryParseDataFrom.day; parsedSchedulePerson[parsedSchedulePerson.length - 1].to.time = 1439; - if (Math.abs(tryParseDataFrom.day - tryParseDataTo.day) > 1) { - addBusyDays(parsedSchedulePerson, tryParseDataFrom.day, tryParseDataTo.day); - } parsedSchedulePerson.push( { from: { @@ -282,31 +279,6 @@ function assignment(assignFrom, assignTo) { assignTo.time = assignFrom.time; } -function addBusyDays(parsedSchedulePerson, dayFrom, dayTo) { - var i = 0; - while ((dayFrom + i) % 7 !== dayTo) { - parsedSchedulePerson.push( - { - from: { - day: -1, - time: 0 - }, - to: { - day: -1, - time: 0 - } - } - ); - parsedSchedulePerson[parsedSchedulePerson.length - 1].from.day = - (dayFrom + i) % 7; - parsedSchedulePerson[parsedSchedulePerson.length - 1].from.time = 0; - parsedSchedulePerson[parsedSchedulePerson.length - 1].to.day = - (dayFrom + i) % 7; - parsedSchedulePerson[parsedSchedulePerson.length - 1].to.time = 1439; - i++; - } -} - function inverseTimePeriods(parsedSchedule, freeTimeSchedule) { for (var index in parsedSchedule) { if (parsedSchedule.hasOwnProperty(index)) { From 0a2008aaa77ba33766d434faa68e5a83cce3dac0 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 23:39:38 +0500 Subject: [PATCH 16/17] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B4=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8=20=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/robbery.js b/robbery.js index 02b280c..829b262 100644 --- a/robbery.js +++ b/robbery.js @@ -129,7 +129,7 @@ function checkBankTimeStrings(workingHours) { for (var index in workingHours) { if (workingHours.hasOwnProperty(index)) { isNotCorrectString = isNotCorrectString || - workingHours[index].search(/^\d{2}:\d{2}\+[1-9]$/) === -1 || + workingHours[index].search(/^\d{2}:\d{2}\+[1-9]\d?$/) === -1 || workingHours[index].length < 7 || workingHours[index].length > 8; } } @@ -188,8 +188,7 @@ function parseDataSchedule(item, gmtBank) { day: -1, time: 0 }; - if (item.search(/^[А-Я]{2}\s\d{2}:\d{2}\+[1-9]$/) === -1 || item.length < 10 || - item.length > 11) { + if (item.search(/^[А-Я]{2}\s\d{2}:\d{2}\+[1-9]$/) === -1 || item.length !== 10) { return dayTime; } dayTime.day = DAYS_OF_WEEK.indexOf(item.substr(0, 2)); From c7d739da91b4c0d3334ad17204932b618d090d72 Mon Sep 17 00:00:00 2001 From: Nazarova Galina Date: Fri, 28 Oct 2016 23:47:51 +0500 Subject: [PATCH 17/17] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B0=20=D1=80=D0=B0=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robbery.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/robbery.js b/robbery.js index 829b262..42b1052 100644 --- a/robbery.js +++ b/robbery.js @@ -26,7 +26,7 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { * @returns {Boolean} */ exists: function () { - if (checkBadParams(schedule, duration, workingHours)) { + if (checkBadParams(duration, workingHours)) { return false; } var timePeriodsOfDays = [[], [], []]; @@ -61,7 +61,7 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { * @returns {String} */ format: function (template) { - if (checkBadParams(schedule, duration, workingHours)) { + if (checkBadParams(duration, workingHours)) { return ''; } var timePeriodsOfDays = [[], [], []]; @@ -101,16 +101,12 @@ exports.getAppropriateMoment = function (schedule, duration, workingHours) { }; -function checkBadParams(schedule, duration, workingHours) { - return (checkSchedule(schedule) || checkDuration(duration) || +function checkBadParams(duration, workingHours) { + return (checkDuration(duration) || checkWorkingHours(workingHours) || duration > parseTime(workingHours.to) - parseTime(workingHours.from)); } -function checkSchedule(schedule) { - return (schedule === null || schedule === undefined); -} - function checkDuration(duration) { return (duration === undefined || Number.isNaN(duration) || duration <= 0 || duration === null);