Fix future posts messing up Catch-up

This commit is contained in:
Lim Chee Aun 2025-02-28 11:26:11 +08:00
parent 44bfbd35d9
commit 6b368987b4

View file

@ -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;