feat: fallback to date-fns.parseISO when date cannot be parsed (#1080)
This commit is contained in:
parent
9b26aff35b
commit
7bd97328ac
@ -82,7 +82,14 @@ const DateTimeControl: FC<WidgetControlProps<string | Date, DateTimeField>> = ({
|
|||||||
return valueToParse;
|
return valueToParse;
|
||||||
}
|
}
|
||||||
|
|
||||||
return storageFormat ? parse(valueToParse, storageFormat, new Date()) : parseISO(valueToParse);
|
if (storageFormat) {
|
||||||
|
const parsed = parse(valueToParse, storageFormat, new Date());
|
||||||
|
// if parsing fails, Invalid Date (NaN) will be returned: fallback to parseISO
|
||||||
|
if (!isNaN(parsed.getTime())) {
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parseISO(valueToParse);
|
||||||
}, [defaultValue, storageFormat, internalValue]);
|
}, [defaultValue, storageFormat, internalValue]);
|
||||||
|
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user