{"action":"created","issue":{"url":"https://api.github.com/repos/bridgedotnet/Bridge/issues/401","labels_url":"https://api.github.com/repos/bridgedotnet/Bridge/issues/401/labels{/name}","comments_url":"https://api.github.com/repos/bridgedotnet/Bridge/issues/401/comments","events_url":"https://api.github.com/repos/bridgedotnet/Bridge/issues/401/events","html_url":"https://github.com/bridgedotnet/Bridge/issues/401","id":103734919,"number":401,"title":"Possible bad script generated when trying to use JSON.parse with a custom reviver","user":{"login":"DanTup","id":1078012,"avatar_url":"https://avatars.githubusercontent.com/u/1078012?v=3","gravatar_id":"","url":"https://api.github.com/users/DanTup","html_url":"https://github.com/DanTup","followers_url":"https://api.github.com/users/DanTup/followers","following_url":"https://api.github.com/users/DanTup/following{/other_user}","gists_url":"https://api.github.com/users/DanTup/gists{/gist_id}","starred_url":"https://api.github.com/users/DanTup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanTup/subscriptions","organizations_url":"https://api.github.com/users/DanTup/orgs","repos_url":"https://api.github.com/users/DanTup/repos","events_url":"https://api.github.com/users/DanTup/events{/privacy}","received_events_url":"https://api.github.com/users/DanTup/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bridgedotnet/Bridge/labels/question","name":"question","color":"207de5"}],"state":"open","locked":false,"assignee":{"login":"LeonidVeriga","id":11466613,"avatar_url":"https://avatars.githubusercontent.com/u/11466613?v=3","gravatar_id":"","url":"https://api.github.com/users/LeonidVeriga","html_url":"https://github.com/LeonidVeriga","followers_url":"https://api.github.com/users/LeonidVeriga/followers","following_url":"https://api.github.com/users/LeonidVeriga/following{/other_user}","gists_url":"https://api.github.com/users/LeonidVeriga/gists{/gist_id}","starred_url":"https://api.github.com/users/LeonidVeriga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeonidVeriga/subscriptions","organizations_url":"https://api.github.com/users/LeonidVeriga/orgs","repos_url":"https://api.github.com/users/LeonidVeriga/repos","events_url":"https://api.github.com/users/LeonidVeriga/events{/privacy}","received_events_url":"https://api.github.com/users/LeonidVeriga/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-08-28T15:03:29Z","updated_at":"2015-09-04T15:28:16Z","closed_at":null,"body":"This could be a bug, or just a request for help/advice ;)\r\n\r\nI'm struggling to get JSON.parse to handle dates correctly. I'm trying to deserialise a class that has a DateTime on it (this class is shared between a WebAPI server and a Bridge client). The JSON representation just has the Date as a string but since my Bridge class is typed as DateTime I need the deserialisation to create a Date from (otherwise code like `myDate.ToLocalDateString()` compiles, but fails at runtime).\r\n\r\nThere's some info on this here:\r\n\r\nhttps://weblog.west-wind.com/posts/2014/Jan/06/JavaScript-JSON-Date-Parsing-and-real-Dates\r\n\r\nI've copied their JS, so I have a `window.JSON.dateParser` function. I would like to call it like this:\r\n\r\n```\r\nvar myData = JSON.parse(json, window.JSON.dateParser);\r\n```\r\n\r\nSo I created a class that looks like this:\r\n\r\n```\r\nstatic class JsonWithDates\r\n{\r\n\tpublic static T Parse<T>(string json)\r\n\t{\r\n\t\tvar parser = Script.Get<dynamic>(\"window.JSON.dateParser\");\r\n\t\treturn JSON.Parse<T>(json, parser);\r\n\t}\r\n}\r\n```\r\n\r\nAnd I'm calling it like this:\r\n\r\n```\r\nvar data = JsonWithDates.Parse<T>(http.ResponseText);\r\n```\r\n\r\nHowever, the JavaScript that gets output is a bit funky:\r\n\r\n```\r\nBridge.define('MyScripts.Services.JsonWithDates', {\r\n    statics: {\r\n        parse: function (T) {\r\n            return Bridge.fn.bind(this, function (json) {\r\n                var parser = window.JSON.dateParser;\r\n                return Bridge.merge(new (), JSON.parse(, ))(json, parser); // This is invalid syntax\r\n            });\r\n        }\r\n    }\r\n});\r\n```\r\n\r\nIs this a bug? Is there a better way to do what I want?\r\n(Ideally, I'd like to convert their JS into C#, but I failed badly in my attempts!)"},"comment":{"url":"https://api.github.com/repos/bridgedotnet/Bridge/issues/comments/137767779","html_url":"https://github.com/bridgedotnet/Bridge/issues/401#issuecomment-137767779","issue_url":"https://api.github.com/repos/bridgedotnet/Bridge/issues/401","id":137767779,"user":{"login":"DanTup","id":1078012,"avatar_url":"https://avatars.githubusercontent.com/u/1078012?v=3","gravatar_id":"","url":"https://api.github.com/users/DanTup","html_url":"https://github.com/DanTup","followers_url":"https://api.github.com/users/DanTup/followers","following_url":"https://api.github.com/users/DanTup/following{/other_user}","gists_url":"https://api.github.com/users/DanTup/gists{/gist_id}","starred_url":"https://api.github.com/users/DanTup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanTup/subscriptions","organizations_url":"https://api.github.com/users/DanTup/orgs","repos_url":"https://api.github.com/users/DanTup/repos","events_url":"https://api.github.com/users/DanTup/events{/privacy}","received_events_url":"https://api.github.com/users/DanTup/received_events","type":"User","site_admin":false},"created_at":"2015-09-04T15:28:16Z","updated_at":"2015-09-04T15:28:16Z","body":"My problem was indeed unrelated to Bridge... the Regex copied from that page didn't allow for not having decimal points in the time (which is what .NET Web API was outputting) eg:\r\n\r\n```\r\n2014-02-01T09:28:56.321-10:00 // worked\r\n2014-02-01T09:28:56-10:00 // did not work\r\n```\r\n\r\nI tweaked the regex and it now works fine :)\r\n\r\n```\r\nvar reISO = /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2}(?:\\.\\d*))(?:Z|(\\+|-)([\\d|:]*))?$/; // old\r\nvar reISO = /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2}(?:\\.\\d*){0,1})(?:Z|(\\+|-)([\\d|:]*))?$/; // new\r\n```"}}