diff --git a/package-lock.json b/package-lock.json index e20190a..aea54a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "js-task-3", "version": "1.0.0", "license": "ISC", "devDependencies": { @@ -10715,13 +10714,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", diff --git a/topic-3/task-1/index.js b/topic-3/task-1/index.js index 94ab761..fff6b80 100644 --- a/topic-3/task-1/index.js +++ b/topic-3/task-1/index.js @@ -17,6 +17,18 @@ @param {number} minutes - Минуты */ function Time(hours, minutes) { -} + if (hours < 0 || hours > 24 || minutes < 0 || minutes > 60 + || !Number.isInteger(hours) || !Number.isInteger(minutes)){ + throw new UserException('Invalid time'); + }; + this.hours = hours; + this.minutes = minutes; +}; +Time.prototype.isEarlier = function(time){ + return time.hours * 60 + time.minutes > this.hours * 60 + this.minutes; +}; +Time.prototype.isLater = function(time){ + return !this.isEarlier(time); +}; 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..179f894 100644 --- a/topic-3/task-2/index.js +++ b/topic-3/task-2/index.js @@ -16,7 +16,18 @@ @param {Time} startTime - Время начала встречи @param {Time} endTime - Время конца встречи */ +const {Time} = require("../task-1"); function Meeting(meetingDate, startTime, endTime) { -} + if (startTime.hours < 8 || endTime.hours > 19 || startTime > endTime + || !(meetingDate instanceof Date) || !(startTime instanceof Time) || !(endTime instanceof Time)){ + throw new UserException('Invalid time'); + }; + 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..d944d72 100644 --- a/topic-3/task-3/index.js +++ b/topic-3/task-3/index.js @@ -12,7 +12,15 @@ */ function Vacation(vacationStartDate, vacationEndDate) { + if (!(vacationEndDate instanceof Date && vacationStartDate instanceof Date) || (vacationStartDate >= vacationEndDate)){ + throw new UserException ("Invalid date vacation"); + }; + this.vacationStartDate = vacationStartDate; + this.vacationEndDate = vacationEndDate; +}; +Vacation.prototype.isDateInVacation = function(date){ + return date >= this.vacationStartDate && date <= this.vacationEndDate; -} +}; 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..15f07ea 100644 --- a/topic-3/task-4/index.js +++ b/topic-3/task-4/index.js @@ -8,7 +8,16 @@ @param {Array} vacations - Массив отпусков */ -function Organaizer(meetings = [], vacations = []) { +const { Meeting } = require("../task-2"); +const { Vacation } = require("../task-3"); + +function Organaizer(meetings = [], vacations = []){ + if(!Array.isArray(meetings) || !Array.isArray(vacations) + ||meetings.some(x => !(x instanceof Meeting)) || meetings.some(x => !(x instanceof Vacation))){ + throw new UserException("Invalid Array"); + }; + this.meetings = meetings; + this.vacations = vacations; }; module.exports.Organaizer = Organaizer; \ No newline at end of file