Skip to content

Commit 7a61215

Browse files
committed
Fix crash on IE 11 caused by passing date to Date constructor (#480)
1 parent be0e9cc commit 7a61215

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Calendar.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ const baseClassName = 'react-calendar';
2525
const allViews = ['century', 'decade', 'year', 'month'];
2626
const allValueTypes = [...allViews.slice(1), 'day'];
2727

28+
function toDate(value) {
29+
if (value instanceof Date) {
30+
return value;
31+
}
32+
33+
return new Date(value);
34+
}
35+
2836
/**
2937
* Returns views array with disallowed values cut off.
3038
*/
@@ -71,7 +79,7 @@ function getValue(value, index) {
7179
return null;
7280
}
7381

74-
const valueDate = new Date(rawValue);
82+
const valueDate = toDate(rawValue);
7583

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

0 commit comments

Comments
 (0)