{"action":"created","comment":{"url":"https://api.github.com/repos/franleplant/reform/pulls/comments/83333739","pull_request_review_id":4185004,"id":83333739,"diff_hunk":"@@ -3,20 +3,41 @@\n import { parseWeek } from '../utils';\n \n // Example week: \"2016-W33\"\n-// TODO: this needs to be improved since some years have 52 weeks\n-const MAX_WEEK = 53\n export default function weekValidator(control) {\n   // Special case for empty values. This is the job of the `required` validator\n   if (!control.value) {\n     return false;\n   }\n \n-  const value = control.value\n-  const [year, week] = parseWeek(value)\n+  const value = control.value;\n+  const [year, week] = parseWeek(value);\n \n   if (!year || !week) {\n-    return true\n+    return true;\n   }\n \n-  return !(0 < year && 1 <= week && week <= MAX_WEEK)\n+  return !(0 < year && 1 <= week && week <= weeksInYear(year));\n+}\n+\n+function weeksInYear(year) {\n+  var d = new Date(year, 11, 31);\n+  var week = getWeekNumber(d)[1];\n+  \n+  return week == 1? getWeekNumber(d.setDate(24))[1] : week;\n+}\n+\n+function getWeekNumber(d) {\n+    // Copy date so don't modify original\n+    d = new Date(+d);\n+    d.setHours(0,0,0);\n+    // Set to nearest Thursday: current date + 4 - current day number\n+    // Make Sunday's day number 7\n+    d.setDate(d.getDate() + 4 - (d.getDay()||7));\n+    // Get first day of year\n+    var yearStart = new Date(d.getFullYear(),0,1);\n+    // Calculate full weeks to nearest Thursday\n+    var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7)","path":"src/officialValidators/week.js","position":43,"original_position":43,"commit_id":"1267abbddfc47cd6f6205a40d04c6e48a23a10e4","original_commit_id":"1267abbddfc47cd6f6205a40d04c6e48a23a10e4","user":{"login":"franleplant","id":1852455,"avatar_url":"https://avatars.githubusercontent.com/u/1852455?v=3","gravatar_id":"","url":"https://api.github.com/users/franleplant","html_url":"https://github.com/franleplant","followers_url":"https://api.github.com/users/franleplant/followers","following_url":"https://api.github.com/users/franleplant/following{/other_user}","gists_url":"https://api.github.com/users/franleplant/gists{/gist_id}","starred_url":"https://api.github.com/users/franleplant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/franleplant/subscriptions","organizations_url":"https://api.github.com/users/franleplant/orgs","repos_url":"https://api.github.com/users/franleplant/repos","events_url":"https://api.github.com/users/franleplant/events{/privacy}","received_events_url":"https://api.github.com/users/franleplant/received_events","type":"User","site_admin":false},"body":"`var` should be replaced with `const`","created_at":"2016-10-13T23:25:51Z","updated_at":"2016-10-13T23:29:29Z","html_url":"https://github.com/franleplant/reform/pull/11#discussion_r83333739","pull_request_url":"https://api.github.com/repos/franleplant/reform/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/franleplant/reform/pulls/comments/83333739"},"html":{"href":"https://github.com/franleplant/reform/pull/11#discussion_r83333739"},"pull_request":{"href":"https://api.github.com/repos/franleplant/reform/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/franleplant/reform/pulls/11","id":89299484,"html_url":"https://github.com/franleplant/reform/pull/11","diff_url":"https://github.com/franleplant/reform/pull/11.diff","patch_url":"https://github.com/franleplant/reform/pull/11.patch","issue_url":"https://api.github.com/repos/franleplant/reform/issues/11","number":11,"state":"open","locked":false,"title":"Issue #8: calculate number of weeks in year.","user":{"login":"babruix","id":462976,"avatar_url":"https://avatars.githubusercontent.com/u/462976?v=3","gravatar_id":"","url":"https://api.github.com/users/babruix","html_url":"https://github.com/babruix","followers_url":"https://api.github.com/users/babruix/followers","following_url":"https://api.github.com/users/babruix/following{/other_user}","gists_url":"https://api.github.com/users/babruix/gists{/gist_id}","starred_url":"https://api.github.com/users/babruix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babruix/subscriptions","organizations_url":"https://api.github.com/users/babruix/orgs","repos_url":"https://api.github.com/users/babruix/repos","events_url":"https://api.github.com/users/babruix/events{/privacy}","received_events_url":"https://api.github.com/users/babruix/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-13T23:12:00Z","updated_at":"2016-10-13T23:29:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4701812420e85990096caa5ef458922f685a62ca","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/franleplant/reform/pulls/11/commits","review_comments_url":"https://api.github.com/repos/franleplant/reform/pulls/11/comments","review_comment_url":"https://api.github.com/repos/franleplant/reform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/franleplant/reform/issues/11/comments","statuses_url":"https://api.github.com/repos/franleplant/reform/statuses/1267abbddfc47cd6f6205a40d04c6e48a23a10e4","head":{"label":"babruix:patch-1","ref":"patch-1","sha":"1267abbddfc47cd6f6205a40d04c6e48a23a10e4","user":{"login":"babruix","id":462976,"avatar_url":"https://avatars.githubusercontent.com/u/462976?v=3","gravatar_id":"","url":"https://api.github.com/users/babruix","html_url":"https://github.com/babruix","followers_url":"https://api.github.com/users/babruix/followers","following_url":"https://api.github.com/users/babruix/following{/other_user}","gists_url":"https://api.github.com/users/babruix/gists{/gist_id}","starred_url":"https://api.github.com/users/babruix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babruix/subscriptions","organizations_url":"https://api.github.com/users/babruix/orgs","repos_url":"https://api.github.com/users/babruix/repos","events_url":"https://api.github.com/users/babruix/events{/privacy}","received_events_url":"https://api.github.com/users/babruix/received_events","type":"User","site_admin":false},"repo":{"id":70855247,"name":"reform","full_name":"babruix/reform","owner":{"login":"babruix","id":462976,"avatar_url":"https://avatars.githubusercontent.com/u/462976?v=3","gravatar_id":"","url":"https://api.github.com/users/babruix","html_url":"https://github.com/babruix","followers_url":"https://api.github.com/users/babruix/followers","following_url":"https://api.github.com/users/babruix/following{/other_user}","gists_url":"https://api.github.com/users/babruix/gists{/gist_id}","starred_url":"https://api.github.com/users/babruix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babruix/subscriptions","organizations_url":"https://api.github.com/users/babruix/orgs","repos_url":"https://api.github.com/users/babruix/repos","events_url":"https://api.github.com/users/babruix/events{/privacy}","received_events_url":"https://api.github.com/users/babruix/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/babruix/reform","description":"React Form Validation lib","fork":true,"url":"https://api.github.com/repos/babruix/reform","forks_url":"https://api.github.com/repos/babruix/reform/forks","keys_url":"https://api.github.com/repos/babruix/reform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/babruix/reform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/babruix/reform/teams","hooks_url":"https://api.github.com/repos/babruix/reform/hooks","issue_events_url":"https://api.github.com/repos/babruix/reform/issues/events{/number}","events_url":"https://api.github.com/repos/babruix/reform/events","assignees_url":"https://api.github.com/repos/babruix/reform/assignees{/user}","branches_url":"https://api.github.com/repos/babruix/reform/branches{/branch}","tags_url":"https://api.github.com/repos/babruix/reform/tags","blobs_url":"https://api.github.com/repos/babruix/reform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/babruix/reform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/babruix/reform/git/refs{/sha}","trees_url":"https://api.github.com/repos/babruix/reform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/babruix/reform/statuses/{sha}","languages_url":"https://api.github.com/repos/babruix/reform/languages","stargazers_url":"https://api.github.com/repos/babruix/reform/stargazers","contributors_url":"https://api.github.com/repos/babruix/reform/contributors","subscribers_url":"https://api.github.com/repos/babruix/reform/subscribers","subscription_url":"https://api.github.com/repos/babruix/reform/subscription","commits_url":"https://api.github.com/repos/babruix/reform/commits{/sha}","git_commits_url":"https://api.github.com/repos/babruix/reform/git/commits{/sha}","comments_url":"https://api.github.com/repos/babruix/reform/comments{/number}","issue_comment_url":"https://api.github.com/repos/babruix/reform/issues/comments{/number}","contents_url":"https://api.github.com/repos/babruix/reform/contents/{+path}","compare_url":"https://api.github.com/repos/babruix/reform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/babruix/reform/merges","archive_url":"https://api.github.com/repos/babruix/reform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/babruix/reform/downloads","issues_url":"https://api.github.com/repos/babruix/reform/issues{/number}","pulls_url":"https://api.github.com/repos/babruix/reform/pulls{/number}","milestones_url":"https://api.github.com/repos/babruix/reform/milestones{/number}","notifications_url":"https://api.github.com/repos/babruix/reform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/babruix/reform/labels{/name}","releases_url":"https://api.github.com/repos/babruix/reform/releases{/id}","deployments_url":"https://api.github.com/repos/babruix/reform/deployments","created_at":"2016-10-13T23:07:18Z","updated_at":"2016-10-13T23:07:19Z","pushed_at":"2016-10-13T23:11:45Z","git_url":"git://github.com/babruix/reform.git","ssh_url":"git@github.com:babruix/reform.git","clone_url":"https://github.com/babruix/reform.git","svn_url":"https://github.com/babruix/reform","homepage":null,"size":809,"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":"franleplant:master","ref":"master","sha":"4539f9f89a8c598427893931ec24f3f4f1545e68","user":{"login":"franleplant","id":1852455,"avatar_url":"https://avatars.githubusercontent.com/u/1852455?v=3","gravatar_id":"","url":"https://api.github.com/users/franleplant","html_url":"https://github.com/franleplant","followers_url":"https://api.github.com/users/franleplant/followers","following_url":"https://api.github.com/users/franleplant/following{/other_user}","gists_url":"https://api.github.com/users/franleplant/gists{/gist_id}","starred_url":"https://api.github.com/users/franleplant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/franleplant/subscriptions","organizations_url":"https://api.github.com/users/franleplant/orgs","repos_url":"https://api.github.com/users/franleplant/repos","events_url":"https://api.github.com/users/franleplant/events{/privacy}","received_events_url":"https://api.github.com/users/franleplant/received_events","type":"User","site_admin":false},"repo":{"id":65921198,"name":"reform","full_name":"franleplant/reform","owner":{"login":"franleplant","id":1852455,"avatar_url":"https://avatars.githubusercontent.com/u/1852455?v=3","gravatar_id":"","url":"https://api.github.com/users/franleplant","html_url":"https://github.com/franleplant","followers_url":"https://api.github.com/users/franleplant/followers","following_url":"https://api.github.com/users/franleplant/following{/other_user}","gists_url":"https://api.github.com/users/franleplant/gists{/gist_id}","starred_url":"https://api.github.com/users/franleplant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/franleplant/subscriptions","organizations_url":"https://api.github.com/users/franleplant/orgs","repos_url":"https://api.github.com/users/franleplant/repos","events_url":"https://api.github.com/users/franleplant/events{/privacy}","received_events_url":"https://api.github.com/users/franleplant/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/franleplant/reform","description":"React Form Validation lib","fork":false,"url":"https://api.github.com/repos/franleplant/reform","forks_url":"https://api.github.com/repos/franleplant/reform/forks","keys_url":"https://api.github.com/repos/franleplant/reform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/franleplant/reform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/franleplant/reform/teams","hooks_url":"https://api.github.com/repos/franleplant/reform/hooks","issue_events_url":"https://api.github.com/repos/franleplant/reform/issues/events{/number}","events_url":"https://api.github.com/repos/franleplant/reform/events","assignees_url":"https://api.github.com/repos/franleplant/reform/assignees{/user}","branches_url":"https://api.github.com/repos/franleplant/reform/branches{/branch}","tags_url":"https://api.github.com/repos/franleplant/reform/tags","blobs_url":"https://api.github.com/repos/franleplant/reform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/franleplant/reform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/franleplant/reform/git/refs{/sha}","trees_url":"https://api.github.com/repos/franleplant/reform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/franleplant/reform/statuses/{sha}","languages_url":"https://api.github.com/repos/franleplant/reform/languages","stargazers_url":"https://api.github.com/repos/franleplant/reform/stargazers","contributors_url":"https://api.github.com/repos/franleplant/reform/contributors","subscribers_url":"https://api.github.com/repos/franleplant/reform/subscribers","subscription_url":"https://api.github.com/repos/franleplant/reform/subscription","commits_url":"https://api.github.com/repos/franleplant/reform/commits{/sha}","git_commits_url":"https://api.github.com/repos/franleplant/reform/git/commits{/sha}","comments_url":"https://api.github.com/repos/franleplant/reform/comments{/number}","issue_comment_url":"https://api.github.com/repos/franleplant/reform/issues/comments{/number}","contents_url":"https://api.github.com/repos/franleplant/reform/contents/{+path}","compare_url":"https://api.github.com/repos/franleplant/reform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/franleplant/reform/merges","archive_url":"https://api.github.com/repos/franleplant/reform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/franleplant/reform/downloads","issues_url":"https://api.github.com/repos/franleplant/reform/issues{/number}","pulls_url":"https://api.github.com/repos/franleplant/reform/pulls{/number}","milestones_url":"https://api.github.com/repos/franleplant/reform/milestones{/number}","notifications_url":"https://api.github.com/repos/franleplant/reform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/franleplant/reform/labels{/name}","releases_url":"https://api.github.com/repos/franleplant/reform/releases{/id}","deployments_url":"https://api.github.com/repos/franleplant/reform/deployments","created_at":"2016-08-17T15:53:32Z","updated_at":"2016-09-16T18:14:01Z","pushed_at":"2016-10-13T23:12:00Z","git_url":"git://github.com/franleplant/reform.git","ssh_url":"git@github.com:franleplant/reform.git","clone_url":"https://github.com/franleplant/reform.git","svn_url":"https://github.com/franleplant/reform","homepage":null,"size":809,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":6,"forks":1,"open_issues":6,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/franleplant/reform/pulls/11"},"html":{"href":"https://github.com/franleplant/reform/pull/11"},"issue":{"href":"https://api.github.com/repos/franleplant/reform/issues/11"},"comments":{"href":"https://api.github.com/repos/franleplant/reform/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/franleplant/reform/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/franleplant/reform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/franleplant/reform/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/franleplant/reform/statuses/1267abbddfc47cd6f6205a40d04c6e48a23a10e4"}}}}
{"actor":{"display_login":"franleplant"}}