Skip to content

Commit

Permalink
Fix crash on IE 11 caused by passing date to Date constructor (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 29, 2021
1 parent be0e9cc commit 7a61215
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const baseClassName = 'react-calendar';
const allViews = ['century', 'decade', 'year', 'month'];
const allValueTypes = [...allViews.slice(1), 'day'];

function toDate(value) {
if (value instanceof Date) {
return value;
}

return new Date(value);
}

/**
* Returns views array with disallowed values cut off.
*/
Expand Down Expand Up @@ -71,7 +79,7 @@ function getValue(value, index) {
return null;
}

const valueDate = new Date(rawValue);
const valueDate = toDate(rawValue);

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

0 comments on commit 7a61215

Please sign in to comment.