Closed knutole closed 8 years ago
Might be problematic:
Moment's validation functions are limited to validating whether a given date/time input string is valid according to a given format. It is assumed that the format(s) are known to the developer. It's not intended to accept the format string itself from a variable source such as the end user.
So no, there are no methods for confirming that the format string is valid.
function checkIfDateIsValidUsingMoment(dateString,format)
{
var m=moment(dateString,format);
return m._pf.charsLeftOver ==0 && m._pf.unusedTokens.length==0 && m._pf.unusedInput.length==0 && m.isValid();
}
Above function takes datestring and format, Moment object has isvalid method but its less usable for strict date validation.
Moment Object has _pf which stores info about parsed date. charsLeftOver: no of chars that do not match (Means extra character, invalid date) unusedInput: array containing details about unused inputs unusedTokens: array containing details about unused tokens
Alternative libraries:
http://arshaw.com/xdate/ https://github.com/abritinthebay/datejs/
related to #29
fixed by a52ea9d
Need to improve how detecting timeseries for different types of data.