{"action":"created","issue":{"url":"https://api.github.com/repos/jwadhams/json-logic-js/issues/6","repository_url":"https://api.github.com/repos/jwadhams/json-logic-js","labels_url":"https://api.github.com/repos/jwadhams/json-logic-js/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/jwadhams/json-logic-js/issues/6/comments","events_url":"https://api.github.com/repos/jwadhams/json-logic-js/issues/6/events","html_url":"https://github.com/jwadhams/json-logic-js/issues/6","id":182566388,"number":6,"title":"[Feature] support dates","user":{"login":"robmurtha","id":1581298,"avatar_url":"https://avatars.githubusercontent.com/u/1581298?v=3","gravatar_id":"","url":"https://api.github.com/users/robmurtha","html_url":"https://github.com/robmurtha","followers_url":"https://api.github.com/users/robmurtha/followers","following_url":"https://api.github.com/users/robmurtha/following{/other_user}","gists_url":"https://api.github.com/users/robmurtha/gists{/gist_id}","starred_url":"https://api.github.com/users/robmurtha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robmurtha/subscriptions","organizations_url":"https://api.github.com/users/robmurtha/orgs","repos_url":"https://api.github.com/users/robmurtha/repos","events_url":"https://api.github.com/users/robmurtha/events{/privacy}","received_events_url":"https://api.github.com/users/robmurtha/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-12T16:05:23Z","updated_at":"2016-10-28T15:30:44Z","closed_at":null,"body":"The general idea is to support the usage of date variables passed in as strings with some form of operator/type specifier to identify them as dates. The primary goal is to support comparison operators.\r\n\r\nExample:\r\n{\"<\":[{\"date\": \"2016-10-01T03:24:00.000Z\"}, {\"date\": \"2016-10-15T03:24:00.000Z\"}]}\r\n\r\nPrototype:\r\n```\r\n\"date\" : function(a) {\r\n  \t \treturn(new Date(a));\r\n  \t}\r\n```\r\n\r\nExample with var - works with date function in place: \r\nrule: {\"<\":[{\"date\":{\"var\":\"submitDate\"}}, {\"date\":{\"var\": \"dueDate\"}}]}\r\ndata: {\"submitDate\":\"2016-10-01T03:24:00.000Z\",\"dueDate\":\"2016-10-15T03:24:00.000Z\"}"},"comment":{"url":"https://api.github.com/repos/jwadhams/json-logic-js/issues/comments/256951940","html_url":"https://github.com/jwadhams/json-logic-js/issues/6#issuecomment-256951940","issue_url":"https://api.github.com/repos/jwadhams/json-logic-js/issues/6","id":256951940,"user":{"login":"jwadhams","id":1613739,"avatar_url":"https://avatars.githubusercontent.com/u/1613739?v=3","gravatar_id":"","url":"https://api.github.com/users/jwadhams","html_url":"https://github.com/jwadhams","followers_url":"https://api.github.com/users/jwadhams/followers","following_url":"https://api.github.com/users/jwadhams/following{/other_user}","gists_url":"https://api.github.com/users/jwadhams/gists{/gist_id}","starred_url":"https://api.github.com/users/jwadhams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwadhams/subscriptions","organizations_url":"https://api.github.com/users/jwadhams/orgs","repos_url":"https://api.github.com/users/jwadhams/repos","events_url":"https://api.github.com/users/jwadhams/events{/privacy}","received_events_url":"https://api.github.com/users/jwadhams/received_events","type":"User","site_admin":false},"created_at":"2016-10-28T15:30:44Z","updated_at":"2016-10-28T15:30:44Z","body":"I still need to write some documentation, but I added the method `jsonLogic.add_operation` yesterday and I think it can solve this case.  Here's an example where string comparison does the wrong thing for two ISO 8601 dates (one Zulu time, the other Pacific time) and then using Date.parse to compare them correctly.\r\n\r\n```js\r\njsonLogic.add_operation('Date', Date);\r\n\r\njsonLogic.apply(\r\n  {\"<\":[\r\n    \"2016-10-01T03:24:00.000Z\",\r\n    \"2016-10-01T03:24:00.000-0800\"\r\n  ]}\r\n); //false\r\n\r\njsonLogic.apply(\r\n  {\"<\":[\r\n    {\"Date.parse\" : \"2016-10-01T03:24:00.000Z\"},\r\n    {\"Date.parse\" : \"2016-10-01T03:24:00.000-0800\"}\r\n  ]}\r\n); //true\r\n```\r\n\r\n\r\nAnd of course it works with `var`s too:\r\n```js\r\njsonLogic.add_operation('Date', Date);\r\n\r\nvar data = {\r\n  gmt : \"2016-10-01T03:24:00.000Z\",\r\n  pst : \"2016-10-01T03:24:00.000-0800\"\r\n};\r\n\r\njsonLogic.apply(\r\n  {\"<\":[\r\n    {\"var\":\"gmt\"},\r\n    {\"var\":\"pst\"}\r\n  ]},\r\n  data\r\n);//false\r\n\r\njsonLogic.apply(\r\n  {\"<\":[\r\n    {\"Date.parse\" : {\"var\":\"gmt\"} },\r\n    {\"Date.parse\" : {\"var\":\"pst\"} }\r\n  ]},\r\n  data\r\n); //true\r\n```\r\n\r\nAnd it's user's choice whether they want to use the built-in Date or they need something heavier duty like moment.js.\r\n\r\nDoes this do what you need it to?"}}
{"actor":{"display_login":"jwadhams"}}