Fixed a bug in isDateValid