Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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