-
Notifications
You must be signed in to change notification settings - Fork 11
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
IgorVM
wants to merge
2
commits into
cripi-javascript:master
Choose a base branch
from
IgorVM:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Имена участников через запятую | ||
* @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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 || "Событие" | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поехало табулирование (табы+пробелы?). Остальное все норм.