Public
Edited
Jan 12, 2023
1 fork
1 star
Insert cell
Insert cell
dates = ["Jan 1, 2020", "Jan 5", "Jul 28", "Sep 4", "Jan 6"]
Insert cell
Insert cell
parsed = {
let year, arr = [];
const parse = d3.timeParse("%b %d, %Y")
for (const date of dates) {
const d = parse(date);
if (d) {
year = d.getFullYear();
arr.push(d);
} else {
const d = parse(`${date}, ${year}`);
if (d > arr[arr.length - 1]) {
arr.push(d);
} else {
year++;
arr.push(parse(`${date}, ${year}`));
}
}
}
return arr;
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more