Fix future posts messing up Catch-up
This commit is contained in:
parent
44bfbd35d9
commit
6b368987b4
1 changed files with 9 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue