feature/fix-rjsf-date-with-abbr-month (#869)

* handle invalid dates better to better support various date formats w/ burnettk

* use getTime to check for date validity instead

---------

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2024-01-09 14:01:32 -05:00 committed by GitHub
parent 687b90bc94
commit 72cedd6e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -41,11 +41,15 @@ const convertDateObjectToFormattedString = (dateObject: Date) => {
};
const dateStringToYMDFormat = (dateString: string) => {
if (dateString && dateString.match(/^\d{2}-\d{2}-\d{4}$/)) {
const newDate = parse(dateString, DATE_FORMAT, new Date());
return format(newDate, 'yyyy-MM-dd');
}
if (dateString && dateString.match(/^\d{4}-\d{2}-\d{2}$/)) {
return dateString;
}
const newDate = parse(dateString, DATE_FORMAT, new Date());
// getTime returns NaN if the date is invalid
if (Number.isNaN(newDate.getTime())) {
return dateString;
}
return format(newDate, 'yyyy-MM-dd');
};
const convertDateAndTimeStringsToDate = (