{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/comments/81382289","pull_request_review_id":2367963,"id":81382289,"diff_hunk":"@@ -0,0 +1,283 @@\n+/**\n+ * Create a formatted, locale-aware string representation of a datetime.\n+ *\n+ * These functions are meant to act as a general localization function\n+ * for server-provided UTC datetimes, creating UI-friendly strings in the user's\n+ * local timezone formatted to the user's preferred language\n+ *\n+ * Most of the heavy lifting is done by the 'moments' js library,\n+ * with the moment-with-locales and moment-timezones add-ons.\n+ *\n+ * By sending preferences data, even in an incomplete state, we can generate the appropriate\n+ * datetime string for surfacing to the user.\n+ *\n+ * @module DateUtils\n+ */\n+\n+\n+/*\n+DATE FORMATS:\n+These were previously called from edx-platform/common/djangoapps/util/date_utils.py,\n+but in an effort to move this to the front-end, they are redefined here and translated into\n+local-aware moment.js formats.\n+\n+DEFAULT_SHORT_DATE_FORMAT\n+example: Jan 01, 2016\n+python: \"%b %d, %Y\"\n+\n+DEFAULT_LONG_DATE_FORMAT\n+example: Friday, January 01, 2016\n+python: \"%A, %B %d, %Y\"\n+\n+DEFAULT_TIME_FORMAT\n+example: Jan 01, 2016 at 15:30\n+python: \"%b %d, %Y at %H:%M\"\n+\n+DEFAULT_DATE_TIME_FORMAT\n+example: Jan 01, 2016 15:30 UTC\n+python: \"%b %d, %Y %H:%M\"\n+*/\n+\n+var DATE_FORMATS = {\n+    DEFAULT_SHORT_DATE_FORMAT: 'll',\n+    DEFAULT_LONG_DATE_FORMAT: 'LLLL',\n+    DEFAULT_TIME_FORMAT: 'LTS z',\n+    DEFAULT_DATE_TIME_FORMAT: 'll HH[:]mm z'\n+};\n+\n+\n+(function(define) {\n+    'use strict';\n+    define([\n+        'jquery',\n+        'edx-ui-toolkit/js/utils/string-utils',\n+        'moment',\n+        'momenttimezone'\n+    ], function(\n+        $,\n+        StringUtils,\n+        moment,\n+        momentTZ\n+        ) {\n+        var DateUtils, isValid, dateObject, userTimezone, localizeTime, timeDisplay, localize;\n+\n+        /**\n+         * Helper function to determine variable/context validity.\n+         *\n+         * @param {string} candidateVariable to test\n+         * @returns {boolean}\n+         */\n+        isValid = function(candidateVariable) {\n+            var valid = true;\n+            if (candidateVariable === undefined) {\n+                valid = false;\n+            } else if (candidateVariable === 'undefined') {\n+                valid = false;\n+            } else if (candidateVariable === '') {\n+                valid = false;\n+            } else if (candidateVariable === 'Invalid date') {\n+                valid = false;\n+            } else {\n+                valid = true;\n+            }\n+            return valid;\n+        };\n+\n+        /**\n+         * Attempt to convert a string to mutable 'moment' datetime object.\n+         *\n+         * The input datetimeString can be just a date, a date and time,\n+         * or a complex date/time string with TZ offset. This is fairly wide-open, as\n+         * many strings will satisfy this requirement.\n+         * (e.g. 01-01-16 and Jan 1, 2016, and 2016-01-01 01:00:00+00:00 will work)\n+         *\n+         * The recommendation is to use a fully informed string, e.g. '2016-01-01 01:00:00+00:00',\n+         * to limit possible date, time, and timezone ambiguities.\n+         *\n+         * @param {string} datetimeString. A string representation of a datetime.\n+         * @returns {object} A moment.js UTC datetime object.\n+         *\n+        */\n+        dateObject = function(datetimeString) {\n+            var utcDateObject;\n+            if (isValid(datetimeString)) {\n+                utcDateObject = moment(datetimeString).utc();\n+            } else {\n+                utcDateObject = '';\n+            }\n+            return utcDateObject;\n+        };\n+\n+        /**\n+         * Attempt to determine user's timezone from preferences, then browser settings.\n+         * Will default to UTC.\n+         *\n+         * @param {string} timezone 'Region/Population_Center' e.g. 'America/New_York'.\n+         * If this is None or undefined, we attempt to determine the TZ from system/browser settings.\n+         * @return {string} Will attempt to return, in this order, the entered, determined, and default (UTC)\n+         * timezone.\n+         *\n+         */\n+        userTimezone = function(timezone) {\n+            var determinedZone;\n+            if (isValid(timezone)) {\n+                determinedZone = timezone;\n+            } else {","path":"src/js/utils/date-utils.js","position":125,"original_position":125,"commit_id":"1d746f7fd0d744c98c2e8d70908d7be0b9a6494e","original_commit_id":"1d746f7fd0d744c98c2e8d70908d7be0b9a6494e","user":{"login":"yro","id":7050866,"avatar_url":"https://avatars.githubusercontent.com/u/7050866?v=3","gravatar_id":"","url":"https://api.github.com/users/yro","html_url":"https://github.com/yro","followers_url":"https://api.github.com/users/yro/followers","following_url":"https://api.github.com/users/yro/following{/other_user}","gists_url":"https://api.github.com/users/yro/gists{/gist_id}","starred_url":"https://api.github.com/users/yro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yro/subscriptions","organizations_url":"https://api.github.com/users/yro/orgs","repos_url":"https://api.github.com/users/yro/repos","events_url":"https://api.github.com/users/yro/events{/privacy}","received_events_url":"https://api.github.com/users/yro/received_events","type":"User","site_admin":false},"body":"Fixed :)","created_at":"2016-09-30T17:29:46Z","updated_at":"2016-09-30T17:29:46Z","html_url":"https://github.com/edx/edx-ui-toolkit/pull/85#discussion_r81382289","pull_request_url":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/85","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/comments/81382289"},"html":{"href":"https://github.com/edx/edx-ui-toolkit/pull/85#discussion_r81382289"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/85"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/85","id":87145075,"html_url":"https://github.com/edx/edx-ui-toolkit/pull/85","diff_url":"https://github.com/edx/edx-ui-toolkit/pull/85.diff","patch_url":"https://github.com/edx/edx-ui-toolkit/pull/85.patch","issue_url":"https://api.github.com/repos/edx/edx-ui-toolkit/issues/85","number":85,"state":"open","locked":false,"title":"DateUtil, moment req, tests","user":{"login":"yro","id":7050866,"avatar_url":"https://avatars.githubusercontent.com/u/7050866?v=3","gravatar_id":"","url":"https://api.github.com/users/yro","html_url":"https://github.com/yro","followers_url":"https://api.github.com/users/yro/followers","following_url":"https://api.github.com/users/yro/following{/other_user}","gists_url":"https://api.github.com/users/yro/gists{/gist_id}","starred_url":"https://api.github.com/users/yro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yro/subscriptions","organizations_url":"https://api.github.com/users/yro/orgs","repos_url":"https://api.github.com/users/yro/repos","events_url":"https://api.github.com/users/yro/events{/privacy}","received_events_url":"https://api.github.com/users/yro/received_events","type":"User","site_admin":false},"body":"## Description\r\nThe intention of this PR is to get some early code review before roping in documentation and product. A formal PR with the requisite requirements below all seen to will follow.\r\n\r\n## [TNL-5565](https://openedx.atlassian.net/browse/TNL-5565)\r\n\r\nThis add a language/timezone aware datetime formatting utility.\r\n\r\n## Manual Test Plan\r\nNone that I am aware of\r\n\r\n## Testing Checklist\r\n- [x] Write unit tests for all new features.\r\n- [ ] Write accessibility (a11y) tests for all new UI.\r\n- [x] Manually test responsive behavior.\r\n\r\n## Non-testing Checklist\r\n- [x] Consider any documentation your change might need, and which users will be affected by this change.\r\n- [x] Consult with the Pattern Library team if adding a new component.\r\n\r\n## Post-review\r\n- [x] Squash commits into discrete sets of changes with descriptive commit messages.\r\n\r\n## Reviewers\r\nTODO: In this section, tag specific reviewers you know will want to have a look at this PR. You can use the checklist below for organization:\r\n\r\n- [ ] @nasthagiri \r\n- [x] @efischer19 \r\n\r\nIf you've been tagged for review, please check your corresponding box once you've given the :+1:.\r\n\r\nWe'll also automatically suggest reviewers for this PR based on the code it touches.\r\n\r\n","created_at":"2016-09-28T15:37:02Z","updated_at":"2016-09-30T17:29:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"95a2e31a0d0183a4e025a420ed171ab9973e831d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/85/commits","review_comments_url":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/85/comments","review_comment_url":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-ui-toolkit/issues/85/comments","statuses_url":"https://api.github.com/repos/edx/edx-ui-toolkit/statuses/1d746f7fd0d744c98c2e8d70908d7be0b9a6494e","head":{"label":"edx:yro_datetime-utils","ref":"yro_datetime-utils","sha":"1d746f7fd0d744c98c2e8d70908d7be0b9a6494e","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":40644985,"name":"edx-ui-toolkit","full_name":"edx/edx-ui-toolkit","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-ui-toolkit","description":"A JavaScript toolkit for building edX user interfaces.","fork":false,"url":"https://api.github.com/repos/edx/edx-ui-toolkit","forks_url":"https://api.github.com/repos/edx/edx-ui-toolkit/forks","keys_url":"https://api.github.com/repos/edx/edx-ui-toolkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-ui-toolkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-ui-toolkit/teams","hooks_url":"https://api.github.com/repos/edx/edx-ui-toolkit/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-ui-toolkit/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-ui-toolkit/events","assignees_url":"https://api.github.com/repos/edx/edx-ui-toolkit/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-ui-toolkit/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-ui-toolkit/tags","blobs_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-ui-toolkit/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-ui-toolkit/languages","stargazers_url":"https://api.github.com/repos/edx/edx-ui-toolkit/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-ui-toolkit/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-ui-toolkit/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-ui-toolkit/subscription","commits_url":"https://api.github.com/repos/edx/edx-ui-toolkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-ui-toolkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-ui-toolkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-ui-toolkit/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-ui-toolkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-ui-toolkit/merges","archive_url":"https://api.github.com/repos/edx/edx-ui-toolkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-ui-toolkit/downloads","issues_url":"https://api.github.com/repos/edx/edx-ui-toolkit/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-ui-toolkit/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-ui-toolkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-ui-toolkit/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-ui-toolkit/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-ui-toolkit/deployments","created_at":"2015-08-13T07:28:13Z","updated_at":"2016-07-13T15:12:40Z","pushed_at":"2016-09-29T16:17:58Z","git_url":"git://github.com/edx/edx-ui-toolkit.git","ssh_url":"git@github.com:edx/edx-ui-toolkit.git","clone_url":"https://github.com/edx/edx-ui-toolkit.git","svn_url":"https://github.com/edx/edx-ui-toolkit","homepage":"http://ui-toolkit.edx.org","size":2191,"stargazers_count":8,"watchers_count":8,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":8,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"b57c996c0f46a41dabed51132812819461105fa9","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":40644985,"name":"edx-ui-toolkit","full_name":"edx/edx-ui-toolkit","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-ui-toolkit","description":"A JavaScript toolkit for building edX user interfaces.","fork":false,"url":"https://api.github.com/repos/edx/edx-ui-toolkit","forks_url":"https://api.github.com/repos/edx/edx-ui-toolkit/forks","keys_url":"https://api.github.com/repos/edx/edx-ui-toolkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-ui-toolkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-ui-toolkit/teams","hooks_url":"https://api.github.com/repos/edx/edx-ui-toolkit/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-ui-toolkit/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-ui-toolkit/events","assignees_url":"https://api.github.com/repos/edx/edx-ui-toolkit/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-ui-toolkit/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-ui-toolkit/tags","blobs_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-ui-toolkit/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-ui-toolkit/languages","stargazers_url":"https://api.github.com/repos/edx/edx-ui-toolkit/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-ui-toolkit/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-ui-toolkit/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-ui-toolkit/subscription","commits_url":"https://api.github.com/repos/edx/edx-ui-toolkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-ui-toolkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-ui-toolkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-ui-toolkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-ui-toolkit/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-ui-toolkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-ui-toolkit/merges","archive_url":"https://api.github.com/repos/edx/edx-ui-toolkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-ui-toolkit/downloads","issues_url":"https://api.github.com/repos/edx/edx-ui-toolkit/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-ui-toolkit/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-ui-toolkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-ui-toolkit/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-ui-toolkit/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-ui-toolkit/deployments","created_at":"2015-08-13T07:28:13Z","updated_at":"2016-07-13T15:12:40Z","pushed_at":"2016-09-29T16:17:58Z","git_url":"git://github.com/edx/edx-ui-toolkit.git","ssh_url":"git@github.com:edx/edx-ui-toolkit.git","clone_url":"https://github.com/edx/edx-ui-toolkit.git","svn_url":"https://github.com/edx/edx-ui-toolkit","homepage":"http://ui-toolkit.edx.org","size":2191,"stargazers_count":8,"watchers_count":8,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/85"},"html":{"href":"https://github.com/edx/edx-ui-toolkit/pull/85"},"issue":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/issues/85"},"comments":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/issues/85/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/85/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/pulls/85/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-ui-toolkit/statuses/1d746f7fd0d744c98c2e8d70908d7be0b9a6494e"}}}}
{"actor":{"display_login":"yro"}}