From b951e57520ef3c267dbf1e40a8856785a02099e8 Mon Sep 17 00:00:00 2001 From: theSweater23 Date: Wed, 17 Mar 2021 15:30:48 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A1=D1=83=D0=BB=D0=B5=D0=B9=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=20=D0=AD=D0=BC=D0=B8=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task_1/index.js | 27 ++++++++++++++++++++++++++- src/task_2/index.js | 33 ++++++++++++++++++++++++++++++++- src/task_3/index.js | 14 +++++++++++++- src/task_4/index.js | 5 ++++- 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/task_1/index.js b/src/task_1/index.js index 2abfd00..53a3dc4 100644 --- a/src/task_1/index.js +++ b/src/task_1/index.js @@ -15,6 +15,31 @@ @param {number} hours - Час @param {number} minutes - Минуты */ -function Time(hours, minutes) { }; +function Time(hours, minutes) { + if (hours >= 24 || minutes >= 60 || hours < 0 || minutes < 0) throw new Error(); + this.hours = hours; + this.minutes = minutes; + }; +Time.prototype.isEarlier = function(time){ + if(time.hours > this.hours) + return true; + else + { + if (time.minutes > this.minutes) + return true; + else return false; + } +}; + +Time.prototype.isLater = function(time){ + if(time.hours < this.hours) + return true; + else + { + if (time.minutes < this.minutes) + return true; + else return false; + } +}; module.exports.Time = Time; diff --git a/src/task_2/index.js b/src/task_2/index.js index f20d7ee..40f9e11 100644 --- a/src/task_2/index.js +++ b/src/task_2/index.js @@ -17,6 +17,37 @@ const { Time } = require('../task_1/index'); @param {Time} startTime - Время начала встречи @param {Time} endTime - Время конца встречи */ -function Meeting(meetingDate, startTime, endTime) { }; +function Meeting(meetingDate, startTime, endTime) { + if (startTime.hours > endTime.hours) + throw new Error(); + else + { + if (startTime.minutes > endTime.minutes && startTime.hours == endTime.hours) + throw new Error(); + } + this.startTime = startTime; + this.meetingDate = meetingDate; + this.endTime = endTime; + }; + +Meeting.prototype.isMeetingInTimeRange = function(start, end){ + if (this.startTime.hours == start.hours) + { + if (this.endTime.hours < end.hours) return true; + else + { + if (end.minutes < this.startTime.minutes) return false; + else return true; + } + } + else + { + if (end.hours < this.endTime.hours) return false; + else + { + if (end.minutes > this.startTime.minutes) return true; + } + } +}; module.exports.Meeting = Meeting; diff --git a/src/task_3/index.js b/src/task_3/index.js index 4212ffa..7f1513d 100644 --- a/src/task_3/index.js +++ b/src/task_3/index.js @@ -11,6 +11,18 @@ @param {Date} vacationEndDate - Время конца отпуска */ -function Vacation(vacationStartDate, vacationEndDate) { }; +function Vacation(vacationStartDate, vacationEndDate) { + if (vacationStartDate > vacationEndDate || + (vacationStartDate.getDate() == vacationEndDate.getDate())) throw new Error(); + this.vacationStartDate = vacationStartDate; + this.vacationEndDate = vacationEndDate; + }; + + Vacation.prototype.isDateInVacation = function(date){ + if (this.vacationStartDate.getDate() <= date.getDate() && this.vacationEndDate.getDate() >= date.getDate() && + date.getFullYear() == this.vacationStartDate.getFullYear()) + return true; + else return false; + }; module.exports.Vacation = Vacation; diff --git a/src/task_4/index.js b/src/task_4/index.js index cae825a..0d4d666 100644 --- a/src/task_4/index.js +++ b/src/task_4/index.js @@ -12,6 +12,9 @@ const { Vacation } = require('../task_3/index'); @param {Array} vacations - Массив отпусков */ -function Organaizer(meetings, vacations) { }; +function Organaizer(meetings, vacations) { + this.meetings = meetings; + this.vacations = vacations; + }; module.exports.Organaizer = Organaizer; From 23253b0d4aa10f2fcd8f94c2af5c2bd576e8fcee Mon Sep 17 00:00:00 2001 From: theSweater23 Date: Thu, 8 Apr 2021 20:44:40 +0500 Subject: [PATCH 2/2] =?UTF-8?q?=D1=81=D1=83=D0=BB=D0=B5=D0=B9=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=20=D1=8D=D0=BC=D0=B8=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task_2/index.js | 33 ++++++++++++++++++++++++++------- src/task_3/index.js | 4 ++-- src/task_5/index.js | 13 +++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/task_2/index.js b/src/task_2/index.js index 40f9e11..07fac1a 100644 --- a/src/task_2/index.js +++ b/src/task_2/index.js @@ -19,11 +19,15 @@ const { Time } = require('../task_1/index'); */ function Meeting(meetingDate, startTime, endTime) { if (startTime.hours > endTime.hours) + { throw new Error(); + } else { - if (startTime.minutes > endTime.minutes && startTime.hours == endTime.hours) + if (startTime.minutes > endTime.minutes && startTime.hours === endTime.hours) + { throw new Error(); + } } this.startTime = startTime; this.meetingDate = meetingDate; @@ -31,21 +35,36 @@ function Meeting(meetingDate, startTime, endTime) { }; Meeting.prototype.isMeetingInTimeRange = function(start, end){ - if (this.startTime.hours == start.hours) + if (this.startTime.hours === start.hours) { - if (this.endTime.hours < end.hours) return true; + if (this.endTime.hours < end.hours) + { + return true; + } else { - if (end.minutes < this.startTime.minutes) return false; - else return true; + if (end.minutes < this.startTime.minutes) + { + return false; + } + else + { + return true; + } } } else { - if (end.hours < this.endTime.hours) return false; + if (end.hours < this.endTime.hours) + { + return false; + } else { - if (end.minutes > this.startTime.minutes) return true; + if (end.minutes > this.startTime.minutes) + { + return true; + } } } }; diff --git a/src/task_3/index.js b/src/task_3/index.js index 7f1513d..26c0036 100644 --- a/src/task_3/index.js +++ b/src/task_3/index.js @@ -13,14 +13,14 @@ function Vacation(vacationStartDate, vacationEndDate) { if (vacationStartDate > vacationEndDate || - (vacationStartDate.getDate() == vacationEndDate.getDate())) throw new Error(); + (vacationStartDate.getDate() === vacationEndDate.getDate())) throw new Error(); this.vacationStartDate = vacationStartDate; this.vacationEndDate = vacationEndDate; }; Vacation.prototype.isDateInVacation = function(date){ if (this.vacationStartDate.getDate() <= date.getDate() && this.vacationEndDate.getDate() >= date.getDate() && - date.getFullYear() == this.vacationStartDate.getFullYear()) + date.getFullYear() === this.vacationStartDate.getFullYear()) return true; else return false; }; diff --git a/src/task_5/index.js b/src/task_5/index.js index c49a642..490fb68 100644 --- a/src/task_5/index.js +++ b/src/task_5/index.js @@ -14,5 +14,18 @@ const { Organaizer } = require('../task_4/index'); Отпуск не попадает в промежуток другого отпуска В промежуток отпуска не назначено никаких встреч */ +Organaizer.prototype.addMeeting = function(meeting){ + this.vacations.forEach(element => { + if (element.isDateInVacation(meeting["meetingDate"])) + return false; + }); + this.meetings.forEach(element => { + if (element.isMeetingInTimeRange(meeting["startTime"], meeting["endTime"]) && + element.meetingDate.getDate() == meeting.meetingDate.getDate()) + return false; + }); + this.meetings.push(meeting); + return true; +}; module.exports.Organaizer = Organaizer;