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

Дз2 #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
79 changes: 79 additions & 0 deletions Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*jslint plusplus: true, browser: true, devel: true */
/**
* Возвращает объект Event
*
* @param {Object} NewEvent Объект - событие
* @param {Number|Date} NewEvent.start Начало события
* @param {Number|Date} NewEvent.end Конец события
* @param {String} [NewEvent.name="Событие"] Имя события
* @param {String} NewEvent.place Место события
* @param {Number} NewEvent.rating Рейтинг события от 0 до 5
* @param {String} NewEvent.comment комментарий, описание события
* @param {String} NewEvent.link ссылка
*
* @example
* Event({
* start: new Date('2011-10-10 14:48:00'),
* end: new Date('2011-10-10 15:48:00'),
* name: "Совещание",
* place: "офис 111",
* rating: 5,
* comment: "взять отчет!!!",
* }
* )
*
* @return {Object}
*/
function datatype(data) {
"use strict";
if (typeof data === 'undefined') {
return false;
}
if (!data.getTime) {
return false;
}
if ('Invalid Date' === data) {
return false;
}
return true;
}
/**
* возвращает true, если data имеет тип дата и она корректна
*/
function ratingtype(rating) {
"use strict";
if (typeof rating !== 'number') {
return false;
}
if (rating > 5 || rating < 0) {
return false;
}
return true;
}
/**
* возвращает true, если rating - число от 0 до 5
*/
function Event(NewEvent) {
"use strict";
if (!datatype(NewEvent.start)) {
alert(NewEvent.start + " не является датой!");
return;
}
if (!datatype(NewEvent.end)) {
alert(NewEvent.end + " не является датой!");
return;
}
if (!ratingtype(NewEvent.rating)) {
alert("введите рейтинг от 0 до 5");
return;
}
return {
"start": NewEvent.start,
"end": NewEvent.end,
"name": NewEvent.name || "Событие",
"place": NewEvent.place,
"rating": NewEvent.rating,
"comment": NewEvent.comment,
"link": NewEvent.link
};
}