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
27 changes: 26 additions & 1 deletion src/task_1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

С такой проверкой время 8:40 будет не раньше чем 10:50, а это логическая ошибка

if (time.minutes > this.minutes)
return true;
else return false;
}
};

Time.prototype.isLater = function(time){
if(time.hours < this.hours)
return true;
else
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут кажется та же логическая ошибка, что и в isEarlier

{
if (time.minutes < this.minutes)
return true;
else return false;
}
};
module.exports.Time = Time;
52 changes: 51 additions & 1 deletion src/task_2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 13 additions & 1 deletion src/task_3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 4 additions & 1 deletion src/task_4/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const { Vacation } = require('../task_3/index');
@param {Array<Vacation>} vacations - Массив отпусков
*/

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачтено на 3 балла

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