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:
parent
687b90bc94
commit
72cedd6e7e
|
@ -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 = (
|
||||
|
|
Loading…
Reference in New Issue