-
-
Save n8osapi/1989655 to your computer and use it in GitHub Desktop.
XDate: Extending the 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
// You can extend the parser by adding a new parsing function to the `XDate.parsers` array. | |
// This function is given a single string argument and should return an XDate if parsing was successful. | |
function parseMDY(str) { | |
// this example parses dates like "month/date/year" | |
var parts = str.split('/'); | |
if (parts.length == 3) { | |
return new XDate( | |
parseInt(parts[2]), // year | |
parseInt(parts[0]), // month | |
parseInt(parts[1]) // date | |
); | |
} | |
} | |
XDate.parsers.push(parseMDY); | |
var d = new XDate("6/8/1986"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment