Skip to content

Instantly share code, notes, and snippets.

@gobengo
Created June 8, 2015 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gobengo/da762911509730fc2ba1 to your computer and use it in GitHub Desktop.
Save gobengo/da762911509730fc2ba1 to your computer and use it in GitHub Desktop.
JavaScript xsd:dateTime Parser
// built from definition: http://books.xmlschemata.org/relaxng/ch19-77049.html
var xsdDateTimePattern = new RegExp([
'(\\d{4})', //year
'-',
'(\\d{2})', // month
'-',
'(\\d{2})', // day
'T',
'(\\d{2})', // hour
':',
'(\\d{2})', // minutes
':',
'(\\d{2}(\\.\\d+)?)', // seconds incl optional decimal fraction
'(Z|[+-](\\d{2}):(\\d{2}))' // time zone
].join(''))
/**
* Return whether the provided string is a valid xsd:dateTime
*/
function isValidXsdDateTime(dateTimeStr) {
var match = dateTimeStr.match(xsdDateTimePattern);
return match;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment