-
Notifications
You must be signed in to change notification settings - Fork 9
Второе ДЗ. #15
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
Open
turboDi
wants to merge
4
commits into
cripi-javascript:master
Choose a base branch
from
turboDi: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
Второе ДЗ. #15
Changes from 1 commit
Commits
Show all changes
4 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 hidden or 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,119 @@ | ||
| /*jslint devel: true */ | ||
| function checkStartDate(date) { | ||
| 'use strict'; | ||
| if (date === null) { | ||
| date = new Date(); | ||
| } else if (!(date instanceof Date && isFinite(date))) { | ||
| throw new Error("Start date is invalid, check syntax"); | ||
| } | ||
| return date; | ||
| } | ||
|
|
||
| function checkEndDate(endDate, startDate) { | ||
| 'use strict'; | ||
| var date; | ||
| if (endDate === null) { | ||
| date = startDate; | ||
| date.setHours(startDate.getHours() + 1); | ||
| } else if (endDate instanceof Date && isFinite(endDate)) { | ||
| date = endDate; | ||
| } else { | ||
| throw new Error("End date is invalid, check syntax"); | ||
| } | ||
| return date; | ||
| } | ||
|
|
||
| var REPEAT = { | ||
| NEVER: {title: "None", value: "+ 0.0.0 0:0"}, | ||
| DAY: {title: "Every Day", value: "+ 1.0.0 0:0"}, | ||
| WEEK: {title: "Every Week", value: "+ 7.0.0 0:0"}, | ||
| TWOWEEK: {title: "Every 2 weeks", value: "+ 14.0.0 0:0"}, | ||
| MONTH: {title: "Every month", value: "+ 0.1.0 0:0"}, | ||
| YEAR: {title: "Every year", value: "+ 0.0.1 0:0"} | ||
| }; | ||
|
|
||
| var ALERT = { | ||
| NONE: {title: "None", value: "+ 0.0.0 0:0"}, | ||
| B5MIN: {title: "5 minutes before", value: "- 0.0.0 0:5"}, | ||
| B15MIN: {title: "15 minutes before", value: "- 0.0.0 0:15"}, | ||
| B30MIN: {title: "30 minutes before", value: "- 0.0.0 0:30"}, | ||
| B1HOUR: {title: "1 hour before", value: "- 0.0.0 1:0"}, | ||
| B1DAY: {title: "1 day before", value: "- 0.0.0 24:0"} | ||
| }; | ||
|
|
||
| function checkAddTime(addTime) { | ||
| 'use strict'; | ||
| var re, splitted; | ||
| re = "([+-]) (\\d?\\d.\\d?\\d.\\d?\\d) (\\d?\\d:\\d?\\d)"; | ||
| splitted = addTime.match(re); | ||
| return splitted.length === 4; | ||
| } | ||
|
|
||
| function checkRepeat(repeat) { | ||
| 'use strict'; | ||
| if (repeat === null) { | ||
| repeat = REPEAT.NEVER; | ||
| } else if (!(repeat.title && repeat.value)) { | ||
| throw new Error("Unknown type of 'repeat' variable"); | ||
| } else if (!checkAddTime(repeat.value)) { | ||
| throw new Error("Add time in 'repeat' variable must have format '+ dd.MM.YY hh:mm'"); | ||
| } | ||
| return repeat; | ||
| } | ||
|
|
||
| function checkAlert(alert) { | ||
| 'use strict'; | ||
| if (alert === null) { | ||
| alert = ALERT.NONE; | ||
| } else if (!(alert.title && alert.value)) { | ||
| throw new Error("Unknown type of 'alert' variable"); | ||
| } else if (!checkAddTime(alert.value)) { | ||
| throw new Error("Add time in 'alert' variable must have format '+ dd.MM.YY hh:mm'"); | ||
| } | ||
| return alert; | ||
| } | ||
|
|
||
| /** | ||
| * Возвращает объект Event | ||
| * | ||
| * @param {String} [title="New Event"] Имя события | ||
| * @param {String} [location] Место события | ||
| * @param {Number|Date} [starts="new Date()"] Начало события | ||
| * @param {Number|Date} [ends="starts + 1"] Конец события | ||
| * @param {Object} [repeat="REPEAT.NEVER"] Периодичность события | ||
| * @param {Object} [alert="ALERT.NONE"] Предупреждение | ||
| * @param {String} [notes] Заметки | ||
| * | ||
| * @example | ||
| * Event("Лекция JavaScript", | ||
| * "УРГУ", | ||
| * new Date('2011-10-10T14:48:00'), | ||
| * new Date('2011-10-10T15:48:00'), | ||
| * REPEAT.WEEK, | ||
| * ALERT.B30MIN, | ||
| * "Вспомнить, что проходили на прошлом занятии") | ||
| * | ||
| * @return {Object} | ||
| */ | ||
| function Event(title, location, starts, ends, repeat, alert, notes) { | ||
| 'use strict'; | ||
| var startDate, endDate; | ||
| try { | ||
| startDate = checkStartDate(starts); | ||
| endDate = checkEndDate(ends, starts); | ||
| repeat = checkRepeat(repeat); | ||
| alert = checkAlert(alert); | ||
| } catch (e) { | ||
| console.log(e.message); | ||
| return; | ||
| } | ||
| return { | ||
| "title": title || "New Event", | ||
| "location": location, | ||
| "startDate": startDate, | ||
| "endDate": endDate, | ||
| "repeat": repeat, | ||
| "alert": alert, | ||
| "notes": notes | ||
| }; | ||
| } | ||
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.
Старайся избегать try catch вместо них лучше явно проверять значения и реагировать на них каким-либо другим образом. В нагруженных скриптах блок try catch может внести деоптимизации JIT и вцелом замедляет работу функции.