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

feat: fallback to date-fns.parseISO when date cannot be parsed #1080

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/core/src/widgets/datetime/DateTimeControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ const DateTimeControl: FC<WidgetControlProps<string | Date, DateTimeField>> = ({
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]);

const handleChange = useCallback(
Expand Down
Loading