{"action":"created","issue":{"url":"https://api.github.com/repos/hapijs/joi/issues/731","labels_url":"https://api.github.com/repos/hapijs/joi/issues/731/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/joi/issues/731/comments","events_url":"https://api.github.com/repos/hapijs/joi/issues/731/events","html_url":"https://github.com/hapijs/joi/issues/731","id":109662389,"number":731,"title":"Any interest in 'today' support for date min and max?","user":{"login":"silviogutierrez","id":92824,"avatar_url":"https://avatars.githubusercontent.com/u/92824?v=3","gravatar_id":"","url":"https://api.github.com/users/silviogutierrez","html_url":"https://github.com/silviogutierrez","followers_url":"https://api.github.com/users/silviogutierrez/followers","following_url":"https://api.github.com/users/silviogutierrez/following{/other_user}","gists_url":"https://api.github.com/users/silviogutierrez/gists{/gist_id}","starred_url":"https://api.github.com/users/silviogutierrez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silviogutierrez/subscriptions","organizations_url":"https://api.github.com/users/silviogutierrez/orgs","repos_url":"https://api.github.com/users/silviogutierrez/repos","events_url":"https://api.github.com/users/silviogutierrez/events{/privacy}","received_events_url":"https://api.github.com/users/silviogutierrez/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hapijs/joi/labels/request","name":"request","color":"c7def8"}],"state":"open","locked":false,"assignee":{"login":"Marsup","id":796194,"avatar_url":"https://avatars.githubusercontent.com/u/796194?v=3","gravatar_id":"","url":"https://api.github.com/users/Marsup","html_url":"https://github.com/Marsup","followers_url":"https://api.github.com/users/Marsup/followers","following_url":"https://api.github.com/users/Marsup/following{/other_user}","gists_url":"https://api.github.com/users/Marsup/gists{/gist_id}","starred_url":"https://api.github.com/users/Marsup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Marsup/subscriptions","organizations_url":"https://api.github.com/users/Marsup/orgs","repos_url":"https://api.github.com/users/Marsup/repos","events_url":"https://api.github.com/users/Marsup/events{/privacy}","received_events_url":"https://api.github.com/users/Marsup/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-10-04T04:19:16Z","updated_at":"2015-10-04T13:24:43Z","closed_at":null,"body":"Please mark this as a question/discussion if you see fit.\r\n\r\nRight now, it's 'now' or something else. Would be neat to have 'today' as an option.\r\n\r\nAs we know, JavaScript doesn't have the concept of pure dates (without times) available. But the general convention is to treat midnight of the current date as the JS `Date` representation.\r\n\r\nWith moment, the comparison would be as easy as `var today = moment().startOf('day')` then `moment(value).isBefore(today)`.\r\n\r\nAny thoughts on this?\r\n\r\nThanks again for a great library.\r\n\r\n-\r\nSilvio"},"comment":{"url":"https://api.github.com/repos/hapijs/joi/issues/comments/145349762","html_url":"https://github.com/hapijs/joi/issues/731#issuecomment-145349762","issue_url":"https://api.github.com/repos/hapijs/joi/issues/731","id":145349762,"user":{"login":"silviogutierrez","id":92824,"avatar_url":"https://avatars.githubusercontent.com/u/92824?v=3","gravatar_id":"","url":"https://api.github.com/users/silviogutierrez","html_url":"https://github.com/silviogutierrez","followers_url":"https://api.github.com/users/silviogutierrez/followers","following_url":"https://api.github.com/users/silviogutierrez/following{/other_user}","gists_url":"https://api.github.com/users/silviogutierrez/gists{/gist_id}","starred_url":"https://api.github.com/users/silviogutierrez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silviogutierrez/subscriptions","organizations_url":"https://api.github.com/users/silviogutierrez/orgs","repos_url":"https://api.github.com/users/silviogutierrez/repos","events_url":"https://api.github.com/users/silviogutierrez/events{/privacy}","received_events_url":"https://api.github.com/users/silviogutierrez/received_events","type":"User","site_admin":false},"created_at":"2015-10-04T13:24:43Z","updated_at":"2015-10-04T13:24:43Z","body":"Timezones is how I ended up needing this feature. My team and I gave it much thought, so hopefully the following helps (warning: some pretty obvious stuff mentioned, but JS makes you reinvent it).\r\n\r\nDates, in languages other than JS, *have* no time zones.\r\n\r\nWhen a client says, launch this rocket on \"October 3rd\", one way or another, they need the end database representation to read `2015-10-03`. *Not* `2015-10-03T00:00:00Z` or something like that.\r\n\r\nThis is the case with other platforms and languages, and databases like MySQL, PostgreSQL, etc. Mongo, popular in the Node world, does store a JavaScript-style `Date` with time.\r\n\r\nNow the server stores `2015-10-03`. How then, do you know when to launch that rocket? Especially if you are say, based in New York. Does that cron job launch it at 1 am GMT on the 3rd? It shouldn't as it isn't `2015-10-03` in New York yet. But this doesn't mean dates have timezones. Rather, it means that the application/server itself has a general timezone.\r\n\r\nIf you're the US military, then this server timezone would be DC, most likely (we know in reality they probably use UTC). So the cron job would say say \"show me all rockets launching today, where today means in the context of Washington DC.\" At 1 am GMT, \"today in Washington DC\" is still `2015-10-02`. Thus the rocket wouldn't launch, and correctly so.\r\n\r\nAnd if your app is international with rocket launchers from all over the world, then you typically store the account holder's timezone and run it under that logic.\r\n\r\nSo to summarize my approach, even in the JS world:\r\n\r\n- Dates have no timezones.\r\n- In the DB, dates should be stored without timezones.\r\n- When performing date logic, you do have to factor in timezones, relevant to the user.\r\n\r\nUltimately, custom validators in Joi will make this straightforward, at least for us. But in the meantime, I hope this is helpful to others, especially NodeJS developers. As a Django developer, this was always extremely helpful to me: https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/ . Particularly the FAQ. It's an example of a platform that got timezones, dates, and times \"right\".\r\n\r\nThanks again for considering this. Completely understand if it's not doable. Happy to come up with the timezone-agnostic date comparison logic for you."}}