{"issue":{"state":"open","created_at":"2011-11-18T11:54:29Z","updated_at":"2011-11-22T02:20:04Z","comments":7,"user":{"gravatar_id":"a8b7add9e591acf027027a1d3bf18b1a","id":129938,"url":"https://api.github.com/users/jorgemanrubia","avatar_url":"https://secure.gravatar.com/avatar/a8b7add9e591acf027027a1d3bf18b1a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"jorgemanrubia"},"body":"Hi,\r\n\r\nI have seen that sometimes, date parsing considers the time while other times it doesn't.\r\n\r\nFor example. In this case it considers 00:00:00 as the time. \r\n\r\n    Date.create('next sunday').toString()\r\n    \"Sun Nov 20 2011 00:00:00 GMT+0100 (CET)\" // It consider 0:00 as the time\r\n    \r\nBut in these cases it considers that you want to keep the current time.\r\n\r\n    Date.create('next month').toString()\r\n    \"Sun Dec 18 2011 12:48:21 GMT+0100 (CET)\"\r\n\r\n    Date.create('1 week from now').toString()\r\n    \"Fri Nov 25 2011 12:48:28 GMT+0100 (CET)\"\r\n\r\nI think this later examples are wrong. If your are asking for \"next month\", it doesn't make sense to set the time. \r\n\r\nCongrats for the lib by the way. It's impressive.\r\n\r\nRegards","assignee":null,"id":2279364,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[],"number":60,"title":"Time inconsistencies depending on the date expression","closed_at":null,"html_url":"https://github.com/andrewplummer/Sugar/issues/60","url":"https://api.github.com/repos/andrewplummer/Sugar/issues/60","milestone":null},"action":"created","comment":{"created_at":"2011-11-22T02:20:04Z","updated_at":"2011-11-22T02:20:04Z","user":{"gravatar_id":"39255341a51574e9651b1094537e7683","id":74646,"url":"https://api.github.com/users/andrewplummer","avatar_url":"https://secure.gravatar.com/avatar/39255341a51574e9651b1094537e7683?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"andrewplummer"},"body":"Yeah I figured that locales might come into play so trying to capture ALL formats for ALL locales may be a bit of a bear if you were considering other languages...\r\n\r\nJust to tease this out with you though... For your purposes, you don't need a time, is that correct? So firstly calling `resetTime` on the date should work for you I think?\r\n\r\nAnd the second goal is to make \"Monday\" mean \"Monday of next week\" properly within the context of your app. That one may be a bit more tricky but here's a suggestion:\r\n\r\n```\r\nvar date = Date.create(INPUT);\r\nvar locale = Date.getLocale(LOCALE_CODE);\r\nif(locale.getWeekday(INPUT) <= new Date().getWeekday()) {\r\n  date.advance({ week: 1 });\r\n}\r\n```\r\n\r\nEssentially what that will do is attempt to find the string (INPUT) in the array of weekdays in the locale and return its numeric value. Then it compares it to the numeric weekday of the current day. So for example, if the input text is \"Monday\", then the first `getWeekday` should return `1`. If the current day is Tuesday, then the second `getWeekday` should return `2` (note that these are 2 different methods, the first is the custom `getWeekday` method on the locale object and the second is JS native method on the date instance). So, if the user input \"monday\", and it's currently \"tuesday\", then advance the date by 1 week. By using the operator `<=`, this will work for \"Monday\" as well, but this is arguable... is saying \"monday\" ON \"monday\" referring to \"today\", or monday of next week? Anyway this way you can define the logic as you see fit. By leveraging the locale object here this code will work across locales too.\r\n\r\nDisclaimer though I think that right the `getWeekday` method on the locale object isn't being flagged as an \"extern\", meaning it's probably being minified and therefor won't exist for you in the production script. So if you try this then please use the non-minified development script I just added `release/sugar-1.1.1.development.js`.\r\n\r\nIf this is a good solution for you then I can include that method in the externs so that other devs can call it as a public method on the locale object (there are a few more).\r\n","id":2829251,"url":"https://api.github.com/repos/andrewplummer/Sugar/issues/comments/2829251"}}