Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/task_1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 17 additions & 1 deletion src/task_2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
15 changes: 14 additions & 1 deletion src/task_3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 6 additions & 1 deletion src/task_4/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const { Vacation } = require('../task_3/index');
@param {Array<Vacation>} vacations - Массив отпусков
*/

function Organaizer(meetings, vacations) { };
class Organaizer {
constructor(meetings, vacations) {
this.meetings = meetings;
this.vacations = vacations;
}
}

module.exports.Organaizer = Organaizer;
19 changes: 19 additions & 0 deletions src/task_5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;