Skip to content

Commit

Permalink
coerce invalid dates to undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Sep 7, 2021
1 parent 24d0897 commit 11c3228
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/scales.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ function coerceNumber(x) {
// rather than rely on Plot.) Any non-string values are coerced to number first
// and treated as milliseconds since UNIX epoch.
function coerceDate(x) {
return x instanceof Date ? x
return x instanceof Date && !isNaN(x) ? x
: typeof x === "string" ? isoParse(x)
: new Date(x == null ? NaN : +x);
: x == null || isNaN(x = +x) ? undefined
: new Date(x);
}

0 comments on commit 11c3228

Please sign in to comment.