From da946fa47707b4f36ca3717f234d7386864bcb8a Mon Sep 17 00:00:00 2001 From: garche Date: Tue, 7 Dec 2021 20:31:38 +0500 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D1=80=D0=BE=D0=B1=D1=8C=D1=91?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=9A=D1=80=D0=B8=D1=81=D1=82=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- topic-3/task-1/index.js | 14 ++++++++++++++ topic-3/task-2/index.js | 13 +++++++++++++ topic-3/task-3/index.js | 8 ++++++++ topic-3/task-4/index.js | 25 +++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/topic-3/task-1/index.js b/topic-3/task-1/index.js index 94ab761..ad340c3 100644 --- a/topic-3/task-1/index.js +++ b/topic-3/task-1/index.js @@ -17,6 +17,20 @@ @param {number} minutes - Минуты */ function Time(hours, minutes) { + + if (typeof (hours) !== "number" && typeof (minutes) !== "number" || !Number.isInteger(minutes) || !Number.isInteger(hours) || hours < 0 || minutes < 0 || hours > 24 || minutes > 60) { + throw new Error() + } + this.hours = hours; + this.minutes = minutes; +} + +Time.prototype.isEarlier = function(time) { + return (time.minutes + time.hours * 60) > (this.hours * 60 + this.minutes); +} + +Time.prototype.isLater = function (time) { + return (time.minutes + time.hours * 60) <= (this.hours * 60 + this.minutes); } module.exports.Time = Time; \ No newline at end of file diff --git a/topic-3/task-2/index.js b/topic-3/task-2/index.js index 166c7d1..352100b 100644 --- a/topic-3/task-2/index.js +++ b/topic-3/task-2/index.js @@ -17,6 +17,19 @@ @param {Time} endTime - Время конца встречи */ function Meeting(meetingDate, startTime, endTime) { + if (!startTime || !endTime || startTime.hours > 19 || startTime.hours < 8 || + startTime.minutes > 59 || startTime.minutes < 0 || + (startTime.minutes + startTime.hours * 60) > (endTime.minutes + endTime.hours * 60) || + endTime.hours > 19 || endTime.hours < 8 || endTime.minutes > 59 || endTime.minutes < 0) { + throw new Error(); + } + + this.meetingDate = meetingDate; + this.startTime = startTime; + this.endTime = endTime; +} +Meeting.prototype.isMeetingInTimeRange = function (start, end) { + return start.isEarlier(this.endTime) && end.isLater(this.startTime); } module.exports.Meeting = Meeting; \ No newline at end of file diff --git a/topic-3/task-3/index.js b/topic-3/task-3/index.js index b5ff228..6afebcd 100644 --- a/topic-3/task-3/index.js +++ b/topic-3/task-3/index.js @@ -13,6 +13,14 @@ function Vacation(vacationStartDate, vacationEndDate) { + if (!vacationStartDate || !vacationEndDate || vacationStartDate >= vacationEndDate) { + throw new Error(); + } + this.vacationEndDate = vacationEndDate; + this.vacationStartDate = vacationStartDate; +} +Vacation.prototype.isDateInVacation = function(Date) { + return this.vacationStartDate <= Date && this.vacationEndDate >= Date; } module.exports.Vacation = Vacation; \ No newline at end of file diff --git a/topic-3/task-4/index.js b/topic-3/task-4/index.js index 7d670e8..6d7a106 100644 --- a/topic-3/task-4/index.js +++ b/topic-3/task-4/index.js @@ -8,7 +8,28 @@ @param {Array} vacations - Массив отпусков */ -function Organaizer(meetings = [], vacations = []) { -}; +function Organaizer(meetings = [], vacations = []) { + const {Meeting} = require("../task-2"); + const {Vacation} = require("../task-3"); + + function Organaizer(meetings = [], vacations = []) { + + this.meetings = []; + this.vacations = []; + + for( const meeting of meetings){ + if(!meeting instanceof Meeting){ + throw new Error() + } + this.meetings.push(meeting) + } + for( const vacation of vacations){ + if(!vacation instanceof Vacation){ + throw new Error() + } + this.meetings.push(vacation) + } + + }; module.exports.Organaizer = Organaizer; \ No newline at end of file