Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Создание объекта Event с проверкой некоторых параметров #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
102 changes: 102 additions & 0 deletions dz2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*jslint regexp: true, browser: true, devel: true */
/**
* Возвращает объект Event
*
* @param {Number|Date} start Начало события
* @param {Number|Date} end Конец события
* @param {Number} rating Рейтинг события от 1 до 5(по умолчанию 1)
* @param {String} [place="Земля"] Место проведения
* @param {Number} numbParticipants Количество участников
* @param {String} participants Имена участников через запятую
Copy link
Member

Choose a reason for hiding this comment

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

Поехало табулирование (табы+пробелы?). Остальное все норм.

* @param {String} regularity Регулярность(ежедневно, еженедельно, ежемесячно(по умолчанию), ежегодно)
* @param {String} [name="Событие"] Имя события
*
* @example
* Event(new Date('2011-10-10T14:48:00'),
* new Date('2011-10-11T14:48:00'),
* 5,
* "Офис",
* 3,
* "Петя,Вася,Коля",
* "Еженедельно",
* "Какой-то комментарий",
* "Встреча")
*
* @return {Object}
*/

function isNumber(n) {
'use strict';
return !isNaN(parseFloat(n)) && isFinite(n);
}

function isDate(input) {
'use strict';
var date, reg = /(0[1-9]|[12][0-9]|3[01]).(0[1-9]|1[012]).(19|20)\d\d/;
if (input.match(reg)) {
date = true;
} else {
date = false;
}
return date;
}

function isTime(input) {
'use strict';
var time, reg = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/;
if (input.match(reg)) {
time = true;
} else {
time = false;
}
return time;
}

function Event(start, end, rate, place, numbParticipants, participants, regularity, comment, name) {
Copy link
Member

Choose a reason for hiding this comment

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

Попробуй уменьшить число аргументов

var data = {
    start: new Date(),
    end: new Date
};

new Event(data);

'use strict';
var startDate, endDate, startTime, endTime, participantsNames = [];
startDate = start.getDate() + '/' + (start.getMonth() + 1) + '/' + start.getFullYear();
endDate = end.getDate() + '/' + (end.getMonth() + 1) + '/' + end.getFullYear();
startTime = start.getUTCHours() + ':' + start.getUTCMinutes();
endTime = end.getUTCHours() + ':' + end.getUTCMinutes();
if (!isDate(startDate)) {
console.log("Please enter start date in dd/mm/yyyy format");
return;
}
if (!isDate(endDate)) {
console.log("Please enter end date in dd/mm/yyyy format");
return;
}
if (!isTime(startTime)) {
console.log("Please enter start date time in 24 format hh:mm");
return;
}
if (!isTime(endTime)) {
console.log("Please enter end date time in 24 format hh:mm");
return;
}
if ((!isNumber(rate) && rate !== "") || (rate > 5 || rate < 1)) {
console.log("Error in rating (Rating must be in range from 1 to 5)");
return;
}
if (!isNumber(numbParticipants)) {
console.log("Wrong number of participants");
return;
}
participantsNames = participants.split(',');
if (participantsNames.length !== numbParticipants) {
console.log("Please check number of participants");
return;
}
return {
"start": start,
"end": end,
"rating": rate || 1,
"place": place || "Земля",
"numbParticipants": numbParticipants,
"participants": participantsNames.toString(),
"regularity": regularity || "Ежемесячно",
"commentary": comment,
"name": name || "Событие"
};
}