{"action":"created","issue":{"url":"https://api.github.com/repos/AddJam/ember-cli-pickadate/issues/22","repository_url":"https://api.github.com/repos/AddJam/ember-cli-pickadate","labels_url":"https://api.github.com/repos/AddJam/ember-cli-pickadate/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/AddJam/ember-cli-pickadate/issues/22/comments","events_url":"https://api.github.com/repos/AddJam/ember-cli-pickadate/issues/22/events","html_url":"https://github.com/AddJam/ember-cli-pickadate/issues/22","id":144788942,"number":22,"title":"Bug when selecting date when number of days in selected month is less than today (e.g. 31 March)","user":{"login":"adrianwong81","id":8654541,"avatar_url":"https://avatars.githubusercontent.com/u/8654541?v=3","gravatar_id":"","url":"https://api.github.com/users/adrianwong81","html_url":"https://github.com/adrianwong81","followers_url":"https://api.github.com/users/adrianwong81/followers","following_url":"https://api.github.com/users/adrianwong81/following{/other_user}","gists_url":"https://api.github.com/users/adrianwong81/gists{/gist_id}","starred_url":"https://api.github.com/users/adrianwong81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adrianwong81/subscriptions","organizations_url":"https://api.github.com/users/adrianwong81/orgs","repos_url":"https://api.github.com/users/adrianwong81/repos","events_url":"https://api.github.com/users/adrianwong81/events{/privacy}","received_events_url":"https://api.github.com/users/adrianwong81/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-31T04:51:50Z","updated_at":"2016-04-07T02:50:44Z","closed_at":null,"body":"For example today is 31 March. When I try to select any date in April (30 days) like 20 April, the result will become 20 May. The same thing happens for June (e.g. 20 June becomes 20 July).\r\n\r\nAfter some debugging I believe the source of the bug appears to be the following 4 lines in the onSelected function:\r\n      var newDate = new Date(date);\r\n      newDate.setYear(dateItem.year);\r\n      newDate.setMonth(dateItem.month);\r\n      newDate.setDate(dateItem.date);\r\n\r\nThe following javascript illustrates the problem:\r\n// Want to select 20 April 2016, the current date is 31 March 2016\r\ntestDate = new Date(2016, 2, 31); console.log(testDate); // 31 March 2016\r\ntestDate.setYear(2016); console.log(testDate); // 31 March 2016, so far so good\r\ntestDate.setMonth(3); console.log(testDate); // 1 May 2016, huh???\r\ntestDate.setDate(20); console.log(testDate); // 20 May 2016, not what we wanted\r\n\r\nFurther details about this javascript date \"bug\" can be found here:\r\nhttp://stackoverflow.com/questions/14680396/the-date-getmonth-method-has-bug\r\n\r\nTo resolve this I recommend you replace the 4 lines previously mentioned with this:\r\n      var newDate = new Date(dateItem.year, dateItem.month, dateItem.date);\r\n"},"comment":{"url":"https://api.github.com/repos/AddJam/ember-cli-pickadate/issues/comments/206669472","html_url":"https://github.com/AddJam/ember-cli-pickadate/issues/22#issuecomment-206669472","issue_url":"https://api.github.com/repos/AddJam/ember-cli-pickadate/issues/22","id":206669472,"user":{"login":"adrianwong81","id":8654541,"avatar_url":"https://avatars.githubusercontent.com/u/8654541?v=3","gravatar_id":"","url":"https://api.github.com/users/adrianwong81","html_url":"https://github.com/adrianwong81","followers_url":"https://api.github.com/users/adrianwong81/followers","following_url":"https://api.github.com/users/adrianwong81/following{/other_user}","gists_url":"https://api.github.com/users/adrianwong81/gists{/gist_id}","starred_url":"https://api.github.com/users/adrianwong81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adrianwong81/subscriptions","organizations_url":"https://api.github.com/users/adrianwong81/orgs","repos_url":"https://api.github.com/users/adrianwong81/repos","events_url":"https://api.github.com/users/adrianwong81/events{/privacy}","received_events_url":"https://api.github.com/users/adrianwong81/received_events","type":"User","site_admin":false},"created_at":"2016-04-07T02:50:44Z","updated_at":"2016-04-07T02:50:44Z","body":"Fyi have created a pull request for the proposed fix for this issue."}}