diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ac44c31 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\index.js" + } + ] +} \ No newline at end of file diff --git a/src/task_5/index.js b/src/task_5/index.js index c49a642..3b1c2ba 100644 --- a/src/task_5/index.js +++ b/src/task_5/index.js @@ -14,5 +14,47 @@ const { Organaizer } = require('../task_4/index'); Отпуск не попадает в промежуток другого отпуска В промежуток отпуска не назначено никаких встреч */ - + Organaizer.prototype.addMeeting = function(meeting) { + for (const vacation of this.vacations) { + if (vacation.isDateInVacation(meeting.meetingDate)) { + return false; + } + } + for (const meeting_ of this.meetings) { + if (meeting_.meetingDate.toString() === meeting.meetingDate.toString()) { + const start = meeting.startTime; + const end = meeting.endTime; + if (meeting_.isMeetingInTimeRange(start, end)) { + return false; + } + } + } + this.meetings.push(meeting); + return true; + } + + Organaizer.prototype.addVacation = function(vacation) { + for (const vacation_ of this.vacations) { + if (isVacationInVacationRange(vacation_, vacation)) { + return false; + } + } + for (const meeting of this.meetings) { + if (vacation.isDateInVacation(meeting.meetingDate)) { + return false; + } + } + this.vacations.push(vacation); + return true; + } + + function isVacationInVacationRange(vacation1, vacation2) { + const start = vacation1.vacationStartDate; + const start1 = vacation2.vacationStartDate; + const end = vacation1.vacationEndDate; + const end1 = vacation2.vacationEndDate; + return !(end < start1 || end1 < start); + } + module.exports.Organaizer = Organaizer; +