Created
October 21, 2015 12:24
-
-
Save finico/62b8cab8e3758af4af77 to your computer and use it in GitHub Desktop.
JSON date parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dateParser(key, value) { | |
if (typeof value === 'string') { | |
var matched = /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)$/.exec(value); | |
if (matched) { | |
return new Date(value); | |
} | |
if (!JSON.parseMsAjaxDate) { | |
return value; | |
} | |
matched = /^\/Date\((d|-|.*)\)[\/|\\]$/.exec(value); | |
if (matched) { | |
var msMatched = matched[1].split(/[-+,.]/); | |
return new Date(msMatched[0] ? +msMatched[0] : 0 - +msMatched[1]); | |
} | |
} | |
return value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment