From 6b368987b4298717232bedfea215a24c67b63456 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 28 Feb 2025 11:26:11 +0800 Subject: [PATCH] Fix future posts messing up Catch-up --- src/pages/catchup.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pages/catchup.jsx b/src/pages/catchup.jsx index 9aa1c858..291db496 100644 --- a/src/pages/catchup.jsx +++ b/src/pages/catchup.jsx @@ -2090,15 +2090,20 @@ function binByTime(data, key, numBins) { ); // Calculate the time span in milliseconds - const range = maxDate.getTime() - minDate.getTime(); + const range = Math.min(maxDate.getTime(), Date.now()) - minDate.getTime(); // Create empty bins and loop through data const bins = Array.from({ length: numBins }, () => []); data.forEach((item) => { const date = new Date(item[key]); - const normalized = (date.getTime() - minDate.getTime()) / range; - const binIndex = Math.floor(normalized * (numBins - 1)); - bins[binIndex].push(item); + if (date.getTime() > Date.now()) { + // Future dates go into the last bin + bins[bins.length - 1].push(item); + } else { + const normalized = (date.getTime() - minDate.getTime()) / range; + const binIndex = Math.floor(normalized * (numBins - 1)); + bins[binIndex].push(item); + } }); return bins;