Skip to content

Commit e75768c

Browse files
authored
Fix crash on IE 11 caused by passing date to Date constructor (#339)
1 parent cd98b1c commit e75768c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/DateInput.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ const defaultMaxDate = new Date(8.64e15);
2424
const allViews = ['century', 'decade', 'year', 'month'];
2525
const allValueTypes = [...allViews.slice(1), 'day'];
2626

27+
function toDate(value) {
28+
if (value instanceof Date) {
29+
return value;
30+
}
31+
32+
return new Date(value);
33+
}
34+
2735
function datesAreDifferent(date1, date2) {
2836
return (
2937
(date1 && !date2)
@@ -50,7 +58,7 @@ function getValue(value, index) {
5058
return null;
5159
}
5260

53-
const valueDate = new Date(rawValue);
61+
const valueDate = toDate(rawValue);
5462

5563
if (isNaN(valueDate.getTime())) {
5664
throw new Error(`Invalid date: ${value}`);

0 commit comments

Comments
 (0)