{"action":"created","issue":{"url":"https://api.github.com/repos/andyearnshaw/Intl.js/issues/145","labels_url":"https://api.github.com/repos/andyearnshaw/Intl.js/issues/145/labels{/name}","comments_url":"https://api.github.com/repos/andyearnshaw/Intl.js/issues/145/comments","events_url":"https://api.github.com/repos/andyearnshaw/Intl.js/issues/145/events","html_url":"https://github.com/andyearnshaw/Intl.js/pull/145","id":119175629,"number":145,"title":"Fix 2-digit date formatting and repeated month symbol for ja/zh","user":{"login":"ianhk","id":3003415,"avatar_url":"https://avatars.githubusercontent.com/u/3003415?v=3","gravatar_id":"","url":"https://api.github.com/users/ianhk","html_url":"https://github.com/ianhk","followers_url":"https://api.github.com/users/ianhk/followers","following_url":"https://api.github.com/users/ianhk/following{/other_user}","gists_url":"https://api.github.com/users/ianhk/gists{/gist_id}","starred_url":"https://api.github.com/users/ianhk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ianhk/subscriptions","organizations_url":"https://api.github.com/users/ianhk/orgs","repos_url":"https://api.github.com/users/ianhk/repos","events_url":"https://api.github.com/users/ianhk/events{/privacy}","received_events_url":"https://api.github.com/users/ianhk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-27T10:52:13Z","updated_at":"2015-11-27T16:08:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/andyearnshaw/Intl.js/pulls/145","html_url":"https://github.com/andyearnshaw/Intl.js/pull/145","diff_url":"https://github.com/andyearnshaw/Intl.js/pull/145.diff","patch_url":"https://github.com/andyearnshaw/Intl.js/pull/145.patch"},"body":"This is a significant change, though fixes the issues for us in key languages so that formats we use are the same as native Intl on FF and Chrome (ignoring the comma difference for one language in Chrome). Tests pass.\r\n\r\n--\r\n\r\nFix issues in intl.js polyfill that meant 2-digit years, days and months were formatted incorrectly, plus the month symbol within Japanese and Chinese date strings was repeated.\r\n\r\n- change the interpretation of CLDR data so that matching a format uses the 'availableFormats skeleton', and formatting an object uses the format string. Previously both tasks used (an adjusted) format string.\r\n- once a format has been located, allow a requested format to be used if it is similar to the located format. e.g.  numbers can be formatted as 2-digit, but short can't.  Previously, once the requested format had been used to locate a nearest match, only the format in that string would be used."},"comment":{"url":"https://api.github.com/repos/andyearnshaw/Intl.js/issues/comments/160167644","html_url":"https://github.com/andyearnshaw/Intl.js/pull/145#issuecomment-160167644","issue_url":"https://api.github.com/repos/andyearnshaw/Intl.js/issues/145","id":160167644,"user":{"login":"ianhk","id":3003415,"avatar_url":"https://avatars.githubusercontent.com/u/3003415?v=3","gravatar_id":"","url":"https://api.github.com/users/ianhk","html_url":"https://github.com/ianhk","followers_url":"https://api.github.com/users/ianhk/followers","following_url":"https://api.github.com/users/ianhk/following{/other_user}","gists_url":"https://api.github.com/users/ianhk/gists{/gist_id}","starred_url":"https://api.github.com/users/ianhk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ianhk/subscriptions","organizations_url":"https://api.github.com/users/ianhk/orgs","repos_url":"https://api.github.com/users/ianhk/repos","events_url":"https://api.github.com/users/ianhk/events{/privacy}","received_events_url":"https://api.github.com/users/ianhk/received_events","type":"User","site_admin":false},"created_at":"2015-11-27T16:08:13Z","updated_at":"2015-11-27T16:08:13Z","body":"Hi @caridy,\r\n\r\nSorry for being cryptic!\r\n\r\nI had two issues - both of which overlap some open issues.\r\na) `Intl.DateTimeFormat(\"{year:'2-digit', month:'2-digit', day:'2-digit'}\")` came out as `m/d/yy` for en-US. i.e. not honouring `2-digit`. \r\nMost regions we need have a similar problem - en-UK comes out as `dd/mm/yyyy` - a 4 digit year.\r\nNative Intl for Chrome/FF and IE11 (not IE11 on W7) get it right with `2-digit` values for day/month and year.\r\nb) Formatting a `short` month for Japanese / Chinese would result in a double month character. One from the CLDR matched date format string, and one from the CLDR short month names.\r\n\r\nI took a look at the spec - http://unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems\r\n\r\nMy interpretation of the spec suggests the `availableFormats` skeleton (the key) should be used for best-fit matching and the format (the value) should be used for building the string. And that the format string should not be taken literally - so that a request for a 2-digit year, but an entry that says 'y' in the format string can be formatted as 2-digits. \r\n\r\nCurrently the polyfill uses the format string for matching (after a bit of tweaking in expandFormat()) and for formatting. And that once located the format string is used without regard to the desired format specified when matching.\r\n\r\nThe change is two part (github makes it look worse than I think it is).\r\n\r\n**src/cldr.js**\r\nChange `createDateTimeFormat()` so that it generates a set of date/time options for both the skeleton (I've called it match) and the format string (called format). The tweaks that `expandFormat()` was making to the format string are no longer required (and had a comment that indicated an area of doubt).\r\n\r\n**src/core.js**\r\nChange the `calculateScore()` function to use the match options (from cldr.js) to calculate best-fit.\r\nOnce found, return the format options (from cldr.js), but allow options to be replaced by those on the original API call - if compatible. i.e. format string may contain d, but I can also format that as dd / 2-digit.\r\n\r\nI'm not sure if it changes the spec - although I believe this is closer to the desired behaviour.\r\n\r\nBoth my issues are fixed by this change.\r\n\r\nThe double symbol issue is fixed because I request a `short` month and match on the skeleton. From ja.json:\r\n\r\n    availableFormats: {\r\n        \"yMMMd\": \"y年M月d日\",\r\n    }\r\n\r\nHere the format string indicates month should be a number followed by the month symbol. My request for a `short` month is ignored as it's not compatible with the CLDR format.\r\n\r\nHope this makes sense. (and understand this is a significant change)\r\n"}}