{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/comments/85888011","pull_request_review_id":6574895,"id":85888011,"diff_hunk":"@@ -1,50 +1,150 @@\n 'use strict';\n \n-/**\n- * Сделано задание на звездочку\n- * Реализовано оба метода и tryLater\n- */\n-exports.isStar = true;\n+exports.isStar = false;\n+var DAYS = ['ПН', 'ВТ', 'СР'];\n+var HOURS = 24;\n+var MINUTES = 60;\n \n /**\n  * @param {Object} schedule – Расписание Банды\n- * @param {Number} duration - Время на ограбление в минутах\n+ * @param {parseInt} duration - Время на ограбление в минутах\n  * @param {Object} workingHours – Время работы банка\n  * @param {String} workingHours.from – Время открытия, например, \"10:00+5\"\n  * @param {String} workingHours.to – Время закрытия, например, \"18:00+5\"\n  * @returns {Object}\n  */\n exports.getAppropriateMoment = function (schedule, duration, workingHours) {\n     console.info(schedule, duration, workingHours);\n+    var busyTimeList = [];\n+    var gmt = parseInt(workingHours.from.slice(6), 10);\n+    var robberyTime;\n+    var keys = Object.keys(schedule);\n+    for (var i = 0; i < keys.length; i++) {\n+        busyTimeList = busyTimeList.concat(getCorrectTime(schedule[keys[i]], gmt));\n+    }\n+    busyTimeList = busyTimeList.concat(getBankWorkTime(workingHours));\n+    busyTimeList.sort(compareStart);\n+    busyTimeList = unionOfIntervals(busyTimeList);\n+    robberyTime = getIntersection(busyTimeList, duration);\n \n     return {\n \n         /**\n          * Найдено ли время\n          * @returns {Boolean}\n          */\n+\n         exists: function () {\n-            return false;\n+            return robberyTime !== null;\n         },\n \n+\n         /**\n          * Возвращает отформатированную строку с часами для ограбления\n          * Например,\n          *   \"Начинаем в %HH:%MM (%DD)\" -> \"Начинаем в 14:59 (СР)\"\n          * @param {String} template\n          * @returns {String}\n          */\n+\n         format: function (template) {\n-            return template;\n+            if (this.exists()) {\n+                var timeDay = Math.floor(robberyTime / MINUTES);\n+                var timeHours = timeDay - Math.floor(timeDay / HOURS) * HOURS;\n+                var timeMin = robberyTime % MINUTES;\n+\n+                return template\n+                        .replace(/%DD/, DAYS[(Math.floor(timeDay / HOURS))])\n+                        .replace(/%HH/, lessThanTen(timeHours))\n+                        .replace(/%MM/, lessThanTen(timeMin));\n+            }\n+\n+            return '';\n         },\n \n         /**\n          * Попробовать найти часы для ограбления позже [*]\n          * @star\n          * @returns {Boolean}\n          */\n+\n         tryLater: function () {\n             return false;\n         }\n     };\n };\n+\n+function lessThanTen(Numb) {\n+    return (Numb < 10) ? ('0' + Numb) : Numb;\n+}\n+\n+function compareStart(a, b) {\n+    return a.start - b.start;\n+}\n+\n+function getCorrectTime(friendSchedule, gmt) {\n+    var intervals = [];\n+    for (var i = 0; i < friendSchedule.length; i++) {\n+        intervals.push({ start: getString(friendSchedule[i].from, gmt),\n+            end: getString(friendSchedule[i].to, gmt) });\n+    }\n+\n+    return intervals;\n+}\n+\n+function getString(stringTime, gmtBank) {\n+    var thiefBusyHours = parseInt(stringTime.slice(3, 5), 10);\n+    var thiefGmt = gmtBank - parseInt(stringTime.slice(9), 10);\n+    var thiefBusyMinutes = parseInt(stringTime.slice(6, 8), 10);\n+    var currentDay = DAYS.indexOf(stringTime.slice(0, 2)) * HOURS;\n+\n+    return (thiefBusyHours + thiefGmt + currentDay) * MINUTES + thiefBusyMinutes;\n+}\n+\n+function parseBankWorkTime(workingHours) {\n+    return MINUTES * parseInt(workingHours.slice(0, 2), 10) +\n+        parseInt(workingHours.slice(3, 5), 10);\n+}\n+\n+function getBankWorkTime(workingHours) {\n+    var workIntervals = [];\n+    var startWorking = parseBankWorkTime(workingHours.from);\n+    var endWorking = parseBankWorkTime(workingHours.to);\n+    workIntervals.push(","path":"robbery.js","position":121,"original_position":121,"commit_id":"3034653513b46004a4af542fb2f60723fc11f13f","original_commit_id":"3034653513b46004a4af542fb2f60723fc11f13f","user":{"login":"nmkname","id":15075843,"avatar_url":"https://avatars.githubusercontent.com/u/15075843?v=3","gravatar_id":"","url":"https://api.github.com/users/nmkname","html_url":"https://github.com/nmkname","followers_url":"https://api.github.com/users/nmkname/followers","following_url":"https://api.github.com/users/nmkname/following{/other_user}","gists_url":"https://api.github.com/users/nmkname/gists{/gist_id}","starred_url":"https://api.github.com/users/nmkname/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmkname/subscriptions","organizations_url":"https://api.github.com/users/nmkname/orgs","repos_url":"https://api.github.com/users/nmkname/repos","events_url":"https://api.github.com/users/nmkname/events{/privacy}","received_events_url":"https://api.github.com/users/nmkname/received_events","type":"User","site_admin":false},"body":"Нам все равно придется делать на два шага меньше, так как первый и последний нельзя задать в цикле без условий, а тут мы знаем точное количество дней, так что строчек кода выйдет столько же, а для трех дней даже меньше.","created_at":"2016-11-01T08:06:35Z","updated_at":"2016-11-01T08:06:35Z","html_url":"https://github.com/urfu-2016/javascript-task-3/pull/39#discussion_r85888011","pull_request_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/comments/85888011"},"html":{"href":"https://github.com/urfu-2016/javascript-task-3/pull/39#discussion_r85888011"},"pull_request":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/39","id":90863615,"html_url":"https://github.com/urfu-2016/javascript-task-3/pull/39","diff_url":"https://github.com/urfu-2016/javascript-task-3/pull/39.diff","patch_url":"https://github.com/urfu-2016/javascript-task-3/pull/39.patch","issue_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/issues/39","number":39,"state":"open","locked":false,"title":"Саитов Владислав","user":{"login":"nmkname","id":15075843,"avatar_url":"https://avatars.githubusercontent.com/u/15075843?v=3","gravatar_id":"","url":"https://api.github.com/users/nmkname","html_url":"https://github.com/nmkname","followers_url":"https://api.github.com/users/nmkname/followers","following_url":"https://api.github.com/users/nmkname/following{/other_user}","gists_url":"https://api.github.com/users/nmkname/gists{/gist_id}","starred_url":"https://api.github.com/users/nmkname/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmkname/subscriptions","organizations_url":"https://api.github.com/users/nmkname/orgs","repos_url":"https://api.github.com/users/nmkname/repos","events_url":"https://api.github.com/users/nmkname/events{/privacy}","received_events_url":"https://api.github.com/users/nmkname/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-25T18:23:32Z","updated_at":"2016-11-01T08:06:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"acfa85c9d8ea5c602506b02067928766adde2c35","assignee":{"login":"chipolinka","id":11631479,"avatar_url":"https://avatars.githubusercontent.com/u/11631479?v=3","gravatar_id":"","url":"https://api.github.com/users/chipolinka","html_url":"https://github.com/chipolinka","followers_url":"https://api.github.com/users/chipolinka/followers","following_url":"https://api.github.com/users/chipolinka/following{/other_user}","gists_url":"https://api.github.com/users/chipolinka/gists{/gist_id}","starred_url":"https://api.github.com/users/chipolinka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipolinka/subscriptions","organizations_url":"https://api.github.com/users/chipolinka/orgs","repos_url":"https://api.github.com/users/chipolinka/repos","events_url":"https://api.github.com/users/chipolinka/events{/privacy}","received_events_url":"https://api.github.com/users/chipolinka/received_events","type":"User","site_admin":false},"assignees":[{"login":"chipolinka","id":11631479,"avatar_url":"https://avatars.githubusercontent.com/u/11631479?v=3","gravatar_id":"","url":"https://api.github.com/users/chipolinka","html_url":"https://github.com/chipolinka","followers_url":"https://api.github.com/users/chipolinka/followers","following_url":"https://api.github.com/users/chipolinka/following{/other_user}","gists_url":"https://api.github.com/users/chipolinka/gists{/gist_id}","starred_url":"https://api.github.com/users/chipolinka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipolinka/subscriptions","organizations_url":"https://api.github.com/users/chipolinka/orgs","repos_url":"https://api.github.com/users/chipolinka/repos","events_url":"https://api.github.com/users/chipolinka/events{/privacy}","received_events_url":"https://api.github.com/users/chipolinka/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/39/commits","review_comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/39/comments","review_comment_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/issues/39/comments","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/statuses/3034653513b46004a4af542fb2f60723fc11f13f","head":{"label":"nmkname:master","ref":"master","sha":"3034653513b46004a4af542fb2f60723fc11f13f","user":{"login":"nmkname","id":15075843,"avatar_url":"https://avatars.githubusercontent.com/u/15075843?v=3","gravatar_id":"","url":"https://api.github.com/users/nmkname","html_url":"https://github.com/nmkname","followers_url":"https://api.github.com/users/nmkname/followers","following_url":"https://api.github.com/users/nmkname/following{/other_user}","gists_url":"https://api.github.com/users/nmkname/gists{/gist_id}","starred_url":"https://api.github.com/users/nmkname/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmkname/subscriptions","organizations_url":"https://api.github.com/users/nmkname/orgs","repos_url":"https://api.github.com/users/nmkname/repos","events_url":"https://api.github.com/users/nmkname/events{/privacy}","received_events_url":"https://api.github.com/users/nmkname/received_events","type":"User","site_admin":false},"repo":{"id":71488555,"name":"javascript-task-3","full_name":"nmkname/javascript-task-3","owner":{"login":"nmkname","id":15075843,"avatar_url":"https://avatars.githubusercontent.com/u/15075843?v=3","gravatar_id":"","url":"https://api.github.com/users/nmkname","html_url":"https://github.com/nmkname","followers_url":"https://api.github.com/users/nmkname/followers","following_url":"https://api.github.com/users/nmkname/following{/other_user}","gists_url":"https://api.github.com/users/nmkname/gists{/gist_id}","starred_url":"https://api.github.com/users/nmkname/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmkname/subscriptions","organizations_url":"https://api.github.com/users/nmkname/orgs","repos_url":"https://api.github.com/users/nmkname/repos","events_url":"https://api.github.com/users/nmkname/events{/privacy}","received_events_url":"https://api.github.com/users/nmkname/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nmkname/javascript-task-3","description":"Задача «0b11 друзей Оушена»","fork":true,"url":"https://api.github.com/repos/nmkname/javascript-task-3","forks_url":"https://api.github.com/repos/nmkname/javascript-task-3/forks","keys_url":"https://api.github.com/repos/nmkname/javascript-task-3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nmkname/javascript-task-3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nmkname/javascript-task-3/teams","hooks_url":"https://api.github.com/repos/nmkname/javascript-task-3/hooks","issue_events_url":"https://api.github.com/repos/nmkname/javascript-task-3/issues/events{/number}","events_url":"https://api.github.com/repos/nmkname/javascript-task-3/events","assignees_url":"https://api.github.com/repos/nmkname/javascript-task-3/assignees{/user}","branches_url":"https://api.github.com/repos/nmkname/javascript-task-3/branches{/branch}","tags_url":"https://api.github.com/repos/nmkname/javascript-task-3/tags","blobs_url":"https://api.github.com/repos/nmkname/javascript-task-3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nmkname/javascript-task-3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nmkname/javascript-task-3/git/refs{/sha}","trees_url":"https://api.github.com/repos/nmkname/javascript-task-3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nmkname/javascript-task-3/statuses/{sha}","languages_url":"https://api.github.com/repos/nmkname/javascript-task-3/languages","stargazers_url":"https://api.github.com/repos/nmkname/javascript-task-3/stargazers","contributors_url":"https://api.github.com/repos/nmkname/javascript-task-3/contributors","subscribers_url":"https://api.github.com/repos/nmkname/javascript-task-3/subscribers","subscription_url":"https://api.github.com/repos/nmkname/javascript-task-3/subscription","commits_url":"https://api.github.com/repos/nmkname/javascript-task-3/commits{/sha}","git_commits_url":"https://api.github.com/repos/nmkname/javascript-task-3/git/commits{/sha}","comments_url":"https://api.github.com/repos/nmkname/javascript-task-3/comments{/number}","issue_comment_url":"https://api.github.com/repos/nmkname/javascript-task-3/issues/comments{/number}","contents_url":"https://api.github.com/repos/nmkname/javascript-task-3/contents/{+path}","compare_url":"https://api.github.com/repos/nmkname/javascript-task-3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nmkname/javascript-task-3/merges","archive_url":"https://api.github.com/repos/nmkname/javascript-task-3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nmkname/javascript-task-3/downloads","issues_url":"https://api.github.com/repos/nmkname/javascript-task-3/issues{/number}","pulls_url":"https://api.github.com/repos/nmkname/javascript-task-3/pulls{/number}","milestones_url":"https://api.github.com/repos/nmkname/javascript-task-3/milestones{/number}","notifications_url":"https://api.github.com/repos/nmkname/javascript-task-3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nmkname/javascript-task-3/labels{/name}","releases_url":"https://api.github.com/repos/nmkname/javascript-task-3/releases{/id}","deployments_url":"https://api.github.com/repos/nmkname/javascript-task-3/deployments","created_at":"2016-10-20T17:44:05Z","updated_at":"2016-10-20T17:44:06Z","pushed_at":"2016-10-31T10:55:31Z","git_url":"git://github.com/nmkname/javascript-task-3.git","ssh_url":"git@github.com:nmkname/javascript-task-3.git","clone_url":"https://github.com/nmkname/javascript-task-3.git","svn_url":"https://github.com/nmkname/javascript-task-3","homepage":"","size":29,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"urfu-2016:master","ref":"master","sha":"bbdd8da0f05059541027bd2efc6038893eaaf2ae","user":{"login":"urfu-2016","id":22170529,"avatar_url":"https://avatars.githubusercontent.com/u/22170529?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2016","html_url":"https://github.com/urfu-2016","followers_url":"https://api.github.com/users/urfu-2016/followers","following_url":"https://api.github.com/users/urfu-2016/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2016/subscriptions","organizations_url":"https://api.github.com/users/urfu-2016/orgs","repos_url":"https://api.github.com/users/urfu-2016/repos","events_url":"https://api.github.com/users/urfu-2016/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2016/received_events","type":"Organization","site_admin":false},"repo":{"id":71448848,"name":"javascript-task-3","full_name":"urfu-2016/javascript-task-3","owner":{"login":"urfu-2016","id":22170529,"avatar_url":"https://avatars.githubusercontent.com/u/22170529?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2016","html_url":"https://github.com/urfu-2016","followers_url":"https://api.github.com/users/urfu-2016/followers","following_url":"https://api.github.com/users/urfu-2016/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2016/subscriptions","organizations_url":"https://api.github.com/users/urfu-2016/orgs","repos_url":"https://api.github.com/users/urfu-2016/repos","events_url":"https://api.github.com/users/urfu-2016/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2016/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/urfu-2016/javascript-task-3","description":"Задача «0b11 друзей Оушена»","fork":false,"url":"https://api.github.com/repos/urfu-2016/javascript-task-3","forks_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/forks","keys_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/teams","hooks_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/hooks","issue_events_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/events","assignees_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/tags","blobs_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/languages","stargazers_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/stargazers","contributors_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/contributors","subscribers_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/subscribers","subscription_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/subscription","commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/merges","archive_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/downloads","issues_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/releases{/id}","deployments_url":"https://api.github.com/repos/urfu-2016/javascript-task-3/deployments","created_at":"2016-10-20T09:49:39Z","updated_at":"2016-10-23T04:31:46Z","pushed_at":"2016-10-31T20:23:08Z","git_url":"git://github.com/urfu-2016/javascript-task-3.git","ssh_url":"git@github.com:urfu-2016/javascript-task-3.git","clone_url":"https://github.com/urfu-2016/javascript-task-3.git","svn_url":"https://github.com/urfu-2016/javascript-task-3","homepage":"","size":111,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":95,"mirror_url":null,"open_issues_count":45,"forks":95,"open_issues":45,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/39"},"html":{"href":"https://github.com/urfu-2016/javascript-task-3/pull/39"},"issue":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/issues/39"},"comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-3/statuses/3034653513b46004a4af542fb2f60723fc11f13f"}}}}
{"actor":{"display_login":"nmkname"}}