From 01ea0f2d70ab91c37fcd07acbd111bb97921b9f1 Mon Sep 17 00:00:00 2001 From: Igor Morozov Date: Wed, 24 Oct 2012 22:51:40 +0600 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0=20Event=20?= =?UTF-8?q?=D1=81=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86=D0=B8=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dz2.js | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 dz2.js diff --git a/dz2.js b/dz2.js new file mode 100644 index 0000000..64012d9 --- /dev/null +++ b/dz2.js @@ -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 Имена участников через запятую + * @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) { + '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 || "Событие" + }; +} \ No newline at end of file From c5554cc189c4e004333399d5b8f5faffbdbba0bf Mon Sep 17 00:00:00 2001 From: Igor Morozov Date: Thu, 1 Nov 2012 00:07:27 +0600 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9E=D0=B1=D1=8A=D0=B5=D0=B4=D0=B8=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=D1=81=D0=B5=20=D0=B2=20=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82,=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dz2.js | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/dz2.js b/dz2.js index 64012d9..72c04c3 100644 --- a/dz2.js +++ b/dz2.js @@ -2,14 +2,16 @@ /** * Возвращает объект Event * - * @param {Number|Date} start Начало события - * @param {Number|Date} end Конец события - * @param {Number} rating Рейтинг события от 1 до 5(по умолчанию 1) - * @param {String} [place="Земля"] Место проведения - * @param {Number} numbParticipants Количество участников - * @param {String} participants Имена участников через запятую - * @param {String} regularity Регулярность(ежедневно, еженедельно, ежемесячно(по умолчанию), ежегодно) - * @param {String} [name="Событие"] Имя события + * @param {Object} EventData Объект - событие + * @param {Number|Date} EventData.start Начало события + * @param {Number|Date} EventData.end Конец события + * @param {Number} EventData.rate Рейтинг события от 1 до 5(по умолчанию 1) + * @param {String} EventData.place [place="Земля"] Место проведения + * @param {Number} EventData.numbParticipants Количество участников + * @param {String} EventData.participants Имена участников через запятую + * @param {String} EventData.regularity Регулярность(ежедневно, еженедельно, ежемесячно(по умолчанию), ежегодно) + * @param {String} EventData.comment Комментарий + * @param {String} EventData.name [name="Событие"] Имя события * * @example * Event(new Date('2011-10-10T14:48:00'), @@ -52,9 +54,18 @@ function isTime(input) { return time; } -function Event(start, end, rate, place, numbParticipants, participants, regularity, comment, name) { +function Event(EventData) { 'use strict'; - var startDate, endDate, startTime, endTime, participantsNames = []; + var startDate, endDate, startTime, endTime, participantsNames = [], start, end, rate, place, numbParticipants, participants, regularity, comment, name; + start = EventData.start; + end = EventData.end; + rate = EventData.rate; + place = EventData.place; + numbParticipants = EventData.numbParticipants; + participants = EventData.participants; + regularity = EventData.regularity; + comment = EventData.comment; + name = EventData.name; startDate = start.getDate() + '/' + (start.getMonth() + 1) + '/' + start.getFullYear(); endDate = end.getDate() + '/' + (end.getMonth() + 1) + '/' + end.getFullYear(); startTime = start.getUTCHours() + ':' + start.getUTCMinutes(); @@ -89,14 +100,14 @@ function Event(start, end, rate, place, numbParticipants, participants, regulari return; } return { - "start": start, - "end": end, - "rating": rate || 1, - "place": place || "Земля", - "numbParticipants": numbParticipants, - "participants": participantsNames.toString(), - "regularity": regularity || "Ежемесячно", - "commentary": comment, - "name": name || "Событие" + "start": EventData.start, + "end": EventData.end, + "rating": EventData.rate || 1, + "place": EventData.place || "Земля", + "numbParticipants": EventData.numbParticipants, + "participants": EventData.participants, + "regularity": EventData.regularity || "Ежемесячно", + "commentary": EventData.comment, + "name": EventData.name || "Событие" }; } \ No newline at end of file