what is the fastest way to check for a valid DateTime? I need to take into account not just that the string cointains year, month, day, hour and minute, but also that the datetime is valid, eg: 2017-02-29 10:00 should be considered not valid because it is 29th in a non leap year.
I have an array of string elements (300k elements) in the format: YYYYMMDDHHmm
, and I need to check each line in the fastest way possible.
Using moment.js to check validity of each elements requires around 5s
in a regular for loop:
for (let i = 0; i < length; i++) {
let el = datetimes[i];
let d = moment.utc(el, "YYYYMMDDHHmm");
d.isValid();
}
Are there faster alternatives?