Fix an array index out of range if an empty date is passed to valid_date