{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/comments/44865211","id":44865211,"diff_hunk":"@@ -3,18 +3,138 @@\n module.exports = function () {\n     return {\n         // Здесь как-то хранится дата ;)\n-        date: null,\n+        theDate: {},\n+\n+        get date() {\n+            return getTimeInMinutes(this.theDate);\n+        },\n+\n+        set date(newDate) {\n+            this.theDate = parseDate(newDate);\n+        },\n \n         // А здесь часовой пояс\n         timezone: null,\n \n         // Выводит дату в переданном формате\n         format: function (pattern) {\n+            var hours = this.theDate.hours + this.timezone;\n+            var day = this.theDate.day;\n+            if (hours < 0) {\n+                hours += 24;\n+                day -= 1;\n+            }\n+            if (hours >= 24) {\n+                hours -= 24;\n+                day += 1;\n+            }\n+            var newDate = {\n+                day: day,\n+                hours: hours,\n+                minutes: this.theDate.minutes\n+            };\n+            var strDate = getStrDate(newDate);\n+            pattern = pattern.replace(/%DD/g, strDate.day);\n+            pattern = pattern.replace(/%HH/g, strDate.hours);\n+            pattern = pattern.replace(/%MM/g, strDate.minutes);\n+            return pattern;\n         },\n \n         // Возвращает кол-во времени между текущей датой и переданной `moment`\n         // в человекопонятном виде\n         fromMoment: function (moment) {\n+            var currentTime = this.date;\n+            var momentTime = moment.date;\n+            var diff = currentTime - momentTime;\n+            if (diff > 0) {\n+                var time = takeTime(diff);\n+                return createStrTime(time);\n+            } else {\n+                return 'Ограбление уже идет!';\n+            }\n         }\n     };\n };\n+\n+function parseDate(date) {\n+    var daysOfWeek = ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ', 'ВС'];\n+    var dayName = date.slice(0, 2);\n+    var day = -1;\n+    for (var i = 0; i < daysOfWeek.length; i++) {\n+        if (dayName === daysOfWeek[i]) {\n+            day = i;\n+            break;\n+        }\n+    }\n+    var zone = parseInt(date.slice(8));\n+    var hours = parseInt(date.slice(3, 5)) - zone; // Перевели в +0\n+    if (hours < 0) {\n+        hours += 24;\n+        day -= 1;\n+    }\n+    if (hours >= 24) {\n+        hours -= 24;\n+        day += 1;\n+    }\n+    day = (day < 0) ? 6 : day;\n+    var minutes = parseInt(date.slice(6, 8));\n+    return {\n+        day: day,\n+        hours: hours,\n+        minutes: minutes\n+    };\n+}\n+\n+function getStrDate(date) {\n+    var hours = (date.hours < 10) ? '0' + date.hours : date.hours;\n+    var minutes = (date.minutes < 10) ? '0' + date.minutes : date.minutes;\n+    var daysOfWeek = ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ', 'ВС'];\n+    var day = daysOfWeek[date.day];\n+    return {\n+        day: day,\n+        hours: hours,\n+        minutes: minutes\n+    };\n+}\n+\n+function getTimeInMinutes(date) {\n+    return (date.day * 24 + date.hours) * 60 + date.minutes;\n+}\n+\n+function takeTime(minutes) {\n+    var days = Math.floor(minutes / (60 * 24));\n+    minutes -= 60 * 24 * days;\n+    var hours = Math.floor(minutes / 60);\n+    minutes -= 60 * hours;\n+    return {\n+        days: days,\n+        hours: hours,\n+        minutes: minutes\n+    };\n+}\n+\n+function createStrTime(time) {","path":"moment.js","position":115,"original_position":115,"commit_id":"0c511b4bf515b0ebde7cd94438cad31430b6a317","original_commit_id":"0c511b4bf515b0ebde7cd94438cad31430b6a317","user":{"login":"gogoleff","id":4534405,"avatar_url":"https://avatars.githubusercontent.com/u/4534405?v=3","gravatar_id":"","url":"https://api.github.com/users/gogoleff","html_url":"https://github.com/gogoleff","followers_url":"https://api.github.com/users/gogoleff/followers","following_url":"https://api.github.com/users/gogoleff/following{/other_user}","gists_url":"https://api.github.com/users/gogoleff/gists{/gist_id}","starred_url":"https://api.github.com/users/gogoleff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogoleff/subscriptions","organizations_url":"https://api.github.com/users/gogoleff/orgs","repos_url":"https://api.github.com/users/gogoleff/repos","events_url":"https://api.github.com/users/gogoleff/events{/privacy}","received_events_url":"https://api.github.com/users/gogoleff/received_events","type":"User","site_admin":false},"body":"getTimeBeforeString","created_at":"2015-11-14T23:16:35Z","updated_at":"2015-11-14T23:16:35Z","html_url":"https://github.com/urfu-2015/javascript-tasks-6/pull/21#discussion_r44865211","pull_request_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/21","_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/comments/44865211"},"html":{"href":"https://github.com/urfu-2015/javascript-tasks-6/pull/21#discussion_r44865211"},"pull_request":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/21"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/21","id":50175767,"html_url":"https://github.com/urfu-2015/javascript-tasks-6/pull/21","diff_url":"https://github.com/urfu-2015/javascript-tasks-6/pull/21.diff","patch_url":"https://github.com/urfu-2015/javascript-tasks-6/pull/21.patch","issue_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/issues/21","number":21,"state":"open","locked":false,"title":"Баженова Анна","user":{"login":"bazhenova","id":12410663,"avatar_url":"https://avatars.githubusercontent.com/u/12410663?v=3","gravatar_id":"","url":"https://api.github.com/users/bazhenova","html_url":"https://github.com/bazhenova","followers_url":"https://api.github.com/users/bazhenova/followers","following_url":"https://api.github.com/users/bazhenova/following{/other_user}","gists_url":"https://api.github.com/users/bazhenova/gists{/gist_id}","starred_url":"https://api.github.com/users/bazhenova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bazhenova/subscriptions","organizations_url":"https://api.github.com/users/bazhenova/orgs","repos_url":"https://api.github.com/users/bazhenova/repos","events_url":"https://api.github.com/users/bazhenova/events{/privacy}","received_events_url":"https://api.github.com/users/bazhenova/received_events","type":"User","site_admin":false},"body":null,"created_at":"2015-11-09T20:52:30Z","updated_at":"2015-11-14T23:16:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a2c95f98b9df222b2f943b8b66a833c91ea10d22","assignee":{"login":"gogoleff","id":4534405,"avatar_url":"https://avatars.githubusercontent.com/u/4534405?v=3","gravatar_id":"","url":"https://api.github.com/users/gogoleff","html_url":"https://github.com/gogoleff","followers_url":"https://api.github.com/users/gogoleff/followers","following_url":"https://api.github.com/users/gogoleff/following{/other_user}","gists_url":"https://api.github.com/users/gogoleff/gists{/gist_id}","starred_url":"https://api.github.com/users/gogoleff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogoleff/subscriptions","organizations_url":"https://api.github.com/users/gogoleff/orgs","repos_url":"https://api.github.com/users/gogoleff/repos","events_url":"https://api.github.com/users/gogoleff/events{/privacy}","received_events_url":"https://api.github.com/users/gogoleff/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/21/commits","review_comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/21/comments","review_comment_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/issues/21/comments","statuses_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/statuses/0c511b4bf515b0ebde7cd94438cad31430b6a317","head":{"label":"bazhenova:master","ref":"master","sha":"0c511b4bf515b0ebde7cd94438cad31430b6a317","user":{"login":"bazhenova","id":12410663,"avatar_url":"https://avatars.githubusercontent.com/u/12410663?v=3","gravatar_id":"","url":"https://api.github.com/users/bazhenova","html_url":"https://github.com/bazhenova","followers_url":"https://api.github.com/users/bazhenova/followers","following_url":"https://api.github.com/users/bazhenova/following{/other_user}","gists_url":"https://api.github.com/users/bazhenova/gists{/gist_id}","starred_url":"https://api.github.com/users/bazhenova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bazhenova/subscriptions","organizations_url":"https://api.github.com/users/bazhenova/orgs","repos_url":"https://api.github.com/users/bazhenova/repos","events_url":"https://api.github.com/users/bazhenova/events{/privacy}","received_events_url":"https://api.github.com/users/bazhenova/received_events","type":"User","site_admin":false},"repo":{"id":45790469,"name":"javascript-tasks-6","full_name":"bazhenova/javascript-tasks-6","owner":{"login":"bazhenova","id":12410663,"avatar_url":"https://avatars.githubusercontent.com/u/12410663?v=3","gravatar_id":"","url":"https://api.github.com/users/bazhenova","html_url":"https://github.com/bazhenova","followers_url":"https://api.github.com/users/bazhenova/followers","following_url":"https://api.github.com/users/bazhenova/following{/other_user}","gists_url":"https://api.github.com/users/bazhenova/gists{/gist_id}","starred_url":"https://api.github.com/users/bazhenova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bazhenova/subscriptions","organizations_url":"https://api.github.com/users/bazhenova/orgs","repos_url":"https://api.github.com/users/bazhenova/repos","events_url":"https://api.github.com/users/bazhenova/events{/privacy}","received_events_url":"https://api.github.com/users/bazhenova/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bazhenova/javascript-tasks-6","description":"Задача к лекции « Объекты, Date, Math» – «0b11 друзей Оушена»","fork":true,"url":"https://api.github.com/repos/bazhenova/javascript-tasks-6","forks_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/forks","keys_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/teams","hooks_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/hooks","issue_events_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/issues/events{/number}","events_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/events","assignees_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/assignees{/user}","branches_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/branches{/branch}","tags_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/tags","blobs_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/git/refs{/sha}","trees_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/statuses/{sha}","languages_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/languages","stargazers_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/stargazers","contributors_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/contributors","subscribers_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/subscribers","subscription_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/subscription","commits_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/commits{/sha}","git_commits_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/git/commits{/sha}","comments_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/comments{/number}","issue_comment_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/issues/comments{/number}","contents_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/contents/{+path}","compare_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/merges","archive_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/downloads","issues_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/issues{/number}","pulls_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/pulls{/number}","milestones_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/milestones{/number}","notifications_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/labels{/name}","releases_url":"https://api.github.com/repos/bazhenova/javascript-tasks-6/releases{/id}","created_at":"2015-11-08T17:22:00Z","updated_at":"2015-11-08T17:22:01Z","pushed_at":"2015-11-09T20:52:30Z","git_url":"git://github.com/bazhenova/javascript-tasks-6.git","ssh_url":"git@github.com:bazhenova/javascript-tasks-6.git","clone_url":"https://github.com/bazhenova/javascript-tasks-6.git","svn_url":"https://github.com/bazhenova/javascript-tasks-6","homepage":"","size":94,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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-2015:master","ref":"master","sha":"a3e2b2a72420bc0195d457a39c732ae5151b04ea","user":{"login":"urfu-2015","id":14800971,"avatar_url":"https://avatars.githubusercontent.com/u/14800971?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2015","html_url":"https://github.com/urfu-2015","followers_url":"https://api.github.com/users/urfu-2015/followers","following_url":"https://api.github.com/users/urfu-2015/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2015/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2015/subscriptions","organizations_url":"https://api.github.com/users/urfu-2015/orgs","repos_url":"https://api.github.com/users/urfu-2015/repos","events_url":"https://api.github.com/users/urfu-2015/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2015/received_events","type":"Organization","site_admin":false},"repo":{"id":45454584,"name":"javascript-tasks-6","full_name":"urfu-2015/javascript-tasks-6","owner":{"login":"urfu-2015","id":14800971,"avatar_url":"https://avatars.githubusercontent.com/u/14800971?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2015","html_url":"https://github.com/urfu-2015","followers_url":"https://api.github.com/users/urfu-2015/followers","following_url":"https://api.github.com/users/urfu-2015/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2015/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2015/subscriptions","organizations_url":"https://api.github.com/users/urfu-2015/orgs","repos_url":"https://api.github.com/users/urfu-2015/repos","events_url":"https://api.github.com/users/urfu-2015/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2015/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/urfu-2015/javascript-tasks-6","description":"Задача к лекции « Объекты, Date, Math» – «0b11 друзей Оушена»","fork":false,"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6","forks_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/forks","keys_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/teams","hooks_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/hooks","issue_events_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/events","assignees_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/tags","blobs_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/languages","stargazers_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/stargazers","contributors_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/contributors","subscribers_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/subscribers","subscription_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/subscription","commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/merges","archive_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/downloads","issues_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/releases{/id}","created_at":"2015-11-03T09:12:41Z","updated_at":"2015-11-03T14:38:37Z","pushed_at":"2015-11-14T21:06:21Z","git_url":"git://github.com/urfu-2015/javascript-tasks-6.git","ssh_url":"git@github.com:urfu-2015/javascript-tasks-6.git","clone_url":"https://github.com/urfu-2015/javascript-tasks-6.git","svn_url":"https://github.com/urfu-2015/javascript-tasks-6","homepage":"","size":1350,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":45,"mirror_url":null,"open_issues_count":26,"forks":45,"open_issues":26,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/21"},"html":{"href":"https://github.com/urfu-2015/javascript-tasks-6/pull/21"},"issue":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/issues/21"},"comments":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-6/statuses/0c511b4bf515b0ebde7cd94438cad31430b6a317"}}}}