Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 7bd9732

Browse files
authored
feat: fallback to date-fns.parseISO when date cannot be parsed (#1080)
1 parent 9b26aff commit 7bd9732

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/core/src/widgets/datetime/DateTimeControl.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ const DateTimeControl: FC<WidgetControlProps<string | Date, DateTimeField>> = ({
8282
return valueToParse;
8383
}
8484

85-
return storageFormat ? parse(valueToParse, storageFormat, new Date()) : parseISO(valueToParse);
85+
if (storageFormat) {
86+
const parsed = parse(valueToParse, storageFormat, new Date());
87+
// if parsing fails, Invalid Date (NaN) will be returned: fallback to parseISO
88+
if (!isNaN(parsed.getTime())) {
89+
return parsed;
90+
}
91+
}
92+
return parseISO(valueToParse);
8693
}, [defaultValue, storageFormat, internalValue]);
8794

8895
const handleChange = useCallback(

0 commit comments

Comments
 (0)