From d09cf3ee3bde9d643965dc4a8eb99b188e4bd0f5 Mon Sep 17 00:00:00 2001 From: Petrov012110 Date: Wed, 4 Aug 2021 21:10:50 +0500 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=20=20?= =?UTF-8?q?=D0=BF=D0=BE=20JS=20=D0=9F=D0=B5=D1=82=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task_1/index.js | 24 +++++++++++++++++++++++- src/task_2/index.js | 18 +++++++++++++++++- src/task_3/index.js | 15 ++++++++++++++- src/task_4/index.js | 7 ++++++- src/task_5/index.js | 19 +++++++++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/task_1/index.js b/src/task_1/index.js index 2abfd00..ab33ba7 100644 --- a/src/task_1/index.js +++ b/src/task_1/index.js @@ -15,6 +15,28 @@ @param {number} hours - Час @param {number} minutes - Минуты */ -function Time(hours, minutes) { }; +class Time { + + constructor(hours, minutes) { + if (hours >= 0 && hours <= 23 && minutes >= 0 && minutes <= 59) { + this.hours = hours; + this.minutes = minutes; + } else { + throw new Error(); + } + } + + isEarlier(time) { + if (time.hours > this.hours) return true; + else if (time.hours === this.hours) return time.minutes > this.minutes; + else return false; + } + + isLater(time) { + if (time.hours < this.hours) return true; + else if (time.hours === this.hours) return time.minutes < this.minutes; + else return false; + } +} module.exports.Time = Time; diff --git a/src/task_2/index.js b/src/task_2/index.js index f20d7ee..94da807 100644 --- a/src/task_2/index.js +++ b/src/task_2/index.js @@ -17,6 +17,22 @@ const { Time } = require('../task_1/index'); @param {Time} startTime - Время начала встречи @param {Time} endTime - Время конца встречи */ -function Meeting(meetingDate, startTime, endTime) { }; +class Meeting { + constructor(meetingDate, startTime, endTime) { + if (startTime.hours >= 8 && endTime.hours <= 19) { + this.meetingDate = meetingDate; + this.startTime = startTime; + this.endTime = endTime; + } else { + throw new Error(); + } + } + isMeetingInTimeRange(start, end) { + if (this.startTime.hours < end.hours && start.hours < this.endTime.hours) return true; + else if (this.startTime.hours === start.hours) return true; + else if (this.startTime.hours === end.hours) return this.startTime.minutes < end.minutes; + else return false; + } +} module.exports.Meeting = Meeting; diff --git a/src/task_3/index.js b/src/task_3/index.js index 4212ffa..39f0982 100644 --- a/src/task_3/index.js +++ b/src/task_3/index.js @@ -11,6 +11,19 @@ @param {Date} vacationEndDate - Время конца отпуска */ -function Vacation(vacationStartDate, vacationEndDate) { }; +class Vacation { + constructor(vacationStartDate, vacationEndDate) { + if (vacationEndDate > vacationStartDate) { + this.vacationEndDate = vacationEndDate; + this.vacationStartDate = vacationStartDate; + } else { + throw new Error(); + } + } + + isDateInVacation(date) { + return (date <= this.vacationEndDate && date >= this.vacationStartDate) ? true : false; + } +} module.exports.Vacation = Vacation; diff --git a/src/task_4/index.js b/src/task_4/index.js index cae825a..72fed5e 100644 --- a/src/task_4/index.js +++ b/src/task_4/index.js @@ -12,6 +12,11 @@ const { Vacation } = require('../task_3/index'); @param {Array} vacations - Массив отпусков */ -function Organaizer(meetings, vacations) { }; +class Organaizer { + constructor(meetings, vacations) { + this.meetings = meetings; + this.vacations = vacations; + } +} module.exports.Organaizer = Organaizer; diff --git a/src/task_5/index.js b/src/task_5/index.js index c49a642..758470c 100644 --- a/src/task_5/index.js +++ b/src/task_5/index.js @@ -14,5 +14,24 @@ const { Organaizer } = require('../task_4/index'); Отпуск не попадает в промежуток другого отпуска В промежуток отпуска не назначено никаких встреч */ +Organaizer.prototype.addMeeting = function (meeting) { + let checkVacation = this.vacations.filter(item => item.isDateInVacation(meeting.meetingDate)); + let checkMeetings = this.meetings.filter(item => { + if (meeting.meetingDate.getTime() === item.meetingDate.getTime()) return item.isMeetingInTimeRange(meeting.startTime, meeting.endTime); + }) + if (!checkVacation.length && !checkMeetings.length) { + this.meetings.push(meeting); + return true; + } else return false; +} +Organaizer.prototype.addVacation = function (vacation) { + let checkVacation = this.vacations.filter(item => item.isDateInVacation(vacation.vacationStartDate) || (item.isDateInVacation(vacation.vacationEndDate))); + let checkMeetings = this.meetings.filter(item => item.meetingDate >= vacation.vacationStartDate && item.meetingDate <= vacation.vacationEndDate); + if (!checkVacation.length && !checkMeetings.length) { + this.vacations.push(vacation); + return true; + } else return false; + +} module.exports.Organaizer = Organaizer;