Skip to content

Instantly share code, notes, and snippets.

@n8osapi
Forked from arshaw/xdate_extending_parser.js
Created March 6, 2012 23:08
Show Gist options
  • Save n8osapi/1989655 to your computer and use it in GitHub Desktop.
Save n8osapi/1989655 to your computer and use it in GitHub Desktop.
XDate: Extending the Parser
// 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