Throw on invalid dates

Avoids a NaN to be returned which makes the timeout go into a loop.