From 7a612159f44d5f9b839922b1b2e2b67bceb9a19e Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Fri, 29 Jan 2021 19:29:01 +0100 Subject: [PATCH] Fix crash on IE 11 caused by passing date to Date constructor (#480) --- src/Calendar.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Calendar.jsx b/src/Calendar.jsx index e678f5cb..76098958 100644 --- a/src/Calendar.jsx +++ b/src/Calendar.jsx @@ -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. */ @@ -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}`);