Skip to content

Commit

Permalink
[#363] Fix RangeError: Invalid time value
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Oct 8, 2024
1 parent ceb1788 commit 093b173
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/answer/DateTimeAnswer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ const DateTimeAnswer = (props) => {

useEffect(() => {
if (props.value) {
setDate(new Date(parse(props.value, datePickerFormat, new Date())));
const parsedDate = parse(props.value, datePickerFormat, new Date());
if (!isNaN(parsedDate.getTime())) {
setDate(parsedDate);
} else {
console.error("Invalid date value:", props.value);
}
} else {
setDate(null);
}
}, []);
}, [props.value, datePickerFormat]);

const dateFormat = FormUtils.resolveDateTimeFormat(
props.question,
Expand Down

0 comments on commit 093b173

Please sign in to comment.