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..07fac1a 100644 --- a/src/task_2/index.js +++ b/src/task_2/index.js @@ -17,6 +17,56 @@ 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..26c0036 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; 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;