{"action":"created","issue":{"url":"https://api.github.com/repos/moment/moment/issues/3862","repository_url":"https://api.github.com/repos/moment/moment","labels_url":"https://api.github.com/repos/moment/moment/issues/3862/labels{/name}","comments_url":"https://api.github.com/repos/moment/moment/issues/3862/comments","events_url":"https://api.github.com/repos/moment/moment/issues/3862/events","html_url":"https://github.com/moment/moment/issues/3862","id":216943482,"number":3862,"title":"isoWeekday returns wrong day","user":{"login":"nirvana74v","id":4522114,"avatar_url":"https://avatars0.githubusercontent.com/u/4522114?v=3","gravatar_id":"","url":"https://api.github.com/users/nirvana74v","html_url":"https://github.com/nirvana74v","followers_url":"https://api.github.com/users/nirvana74v/followers","following_url":"https://api.github.com/users/nirvana74v/following{/other_user}","gists_url":"https://api.github.com/users/nirvana74v/gists{/gist_id}","starred_url":"https://api.github.com/users/nirvana74v/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nirvana74v/subscriptions","organizations_url":"https://api.github.com/users/nirvana74v/orgs","repos_url":"https://api.github.com/users/nirvana74v/repos","events_url":"https://api.github.com/users/nirvana74v/events{/privacy}","received_events_url":"https://api.github.com/users/nirvana74v/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-03-25T02:39:33Z","updated_at":"2017-03-28T03:28:01Z","closed_at":"2017-03-28T03:28:01Z","body":"isoWeekday doesn't reliably return weekday\r\n\r\nSteps to reproduce:\r\n\r\nCreate a function in NodeJS application,\r\n```javascript\r\nfunction checkDay() {\r\n        var fdate = moment().isoWeekday(3); // Returns Tuesday\r\n        var fdt = fdate.tz(\"America/Winnipeg\").format(\"MM-DD-YYYY\");\r\n        var dtStart = moment(fdt + \" 17:00\",\"MM-DD-YYYY HH:mm\"); \r\n        var pastdate = moment().isoWeekday(6); // Returns Friday\r\n        var pastdt = pastdate.tz(\"America/Winnipeg\").format(\"MM-DD-YYYY\");\r\n        var dtEnd = moment(pastdt + \" 23:59:59\",\"MM-DD-YYYY HH:mm:ss\");\r\n\r\n        console.log(logTag + \"Start Date :\" + dtStart + \" - End Date :\" + dtEnd);\r\n        console.log(JSON.stringify(data));\r\n}\r\n```\r\n**Output on Server:** checkNextdate:Start Date :1490115600000 - End Date :1490486399000\r\n{\"start\":\"03-21-2017 17:00\",\"end\":\"03-24-2017 23:59\"}\r\n\r\n**NodeJS:** v7.2.1\r\n\r\n**OS:** Linux ip-172-31-43-97 4.4.30-32.54.amzn1.x86_64 #1 SMP Thu Nov 10 15:52:05 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux\r\n\r\n**Date executed:** 03/24/2017\r\n\r\nIf you are reporting an issue, please run the following code in the environment you are using and include the output:\r\n```js\r\nconsole.log( (new Date()).toString())\r\n*  - Sat Mar 25 2017 02:28:28 GMT+0000 (UTC)*\r\nconsole.log((new Date()).toLocaleString())\r\n*  - 3/25/2017, 2:28:28 AM*\r\nconsole.log( (new Date()).getTimezoneOffset())\r\n*  - 0*\r\nconsole.log( navigator.userAgent)\r\n* - NodeJS app so no value*\r\nconsole.log(moment.version)\r\n*- 2.18.1*\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/moment/moment/issues/comments/289652305","html_url":"https://github.com/moment/moment/issues/3862#issuecomment-289652305","issue_url":"https://api.github.com/repos/moment/moment/issues/3862","id":289652305,"user":{"login":"icambron","id":244988,"avatar_url":"https://avatars0.githubusercontent.com/u/244988?v=3","gravatar_id":"","url":"https://api.github.com/users/icambron","html_url":"https://github.com/icambron","followers_url":"https://api.github.com/users/icambron/followers","following_url":"https://api.github.com/users/icambron/following{/other_user}","gists_url":"https://api.github.com/users/icambron/gists{/gist_id}","starred_url":"https://api.github.com/users/icambron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/icambron/subscriptions","organizations_url":"https://api.github.com/users/icambron/orgs","repos_url":"https://api.github.com/users/icambron/repos","events_url":"https://api.github.com/users/icambron/events{/privacy}","received_events_url":"https://api.github.com/users/icambron/received_events","type":"User","site_admin":false},"created_at":"2017-03-28T03:28:01Z","updated_at":"2017-03-28T03:28:01Z","body":"So, I don't totally understand what you expect that code to do, but here's some hopefully helpful stuff:\r\n\r\n```js\r\n>  moment().isoWeekday(3).isoWeekday()\r\n3\r\n>  moment().isoWeekday(6).isoWeekday()\r\n6\r\n```\r\n\r\nSo we know those work.\r\n\r\n```js\r\n       var fdate = moment().isoWeekday(3); \r\n       var fdt = fdate.tz(\"America/Winnipeg\").format(\"MM-DD-YYYY\");\r\n       var dtStart = moment(fdt + \" 17:00\",\"MM-DD-YYYY HH:mm\"); \r\n```\r\n\r\nI don't know if this does what you think it does. Unless otherwise specified, values passed into the parser are interpreted as local time, in this case UTC. Remember that `dstStart` is just a string; it doesn't know it's in Winnipeg time. Thus neither does the parser.\r\n\r\nSo for example, let's say it's currently 2:00 in the morning UTC. You switch the day of the week Tuesday so now the time is 2:00 on Tuesday UTC.  In Winnipeg time that's 20:00  on Monday so your format string gives that date. Reparsing that date in UTC but with 17:00 tacked on that's 17:00 on Monday UTC, which is 11:00 on Monday in Winnipeg.\r\n\r\nYou didn't say what you were trying to do, but my guess is that's not it. In general, using the parser to set the time will lead to mistakes. If I were guessing what you were trying to do, I'd say something like this:\r\n\r\n```js\r\nvar start = moment()\r\n  .tz(\"America/Winnipeg\")\r\n  .isoWeekday(3)\r\n  .hour(17)\r\n  .minute(0)\r\n  .second(0)\r\n  .millisecond(0);\r\nvar end = moment()\r\n  .tz(\"America/Winnipeg\")\r\n  .isoWeekday(6)\r\n  .endOf('day');\r\n```\r\n\r\nIf that's not what you were trying to do, @ me with your specific expectations for the return values of specific calls to Moment and I will reopen the issue."}}
{"actor":{"display_login":"icambron"}}