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
|
// 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
|
// Create empty bins and loop through data
|
||||||
const bins = Array.from({ length: numBins }, () => []);
|
const bins = Array.from({ length: numBins }, () => []);
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
const date = new Date(item[key]);
|
const date = new Date(item[key]);
|
||||||
const normalized = (date.getTime() - minDate.getTime()) / range;
|
if (date.getTime() > Date.now()) {
|
||||||
const binIndex = Math.floor(normalized * (numBins - 1));
|
// Future dates go into the last bin
|
||||||
bins[binIndex].push(item);
|
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;
|
return bins;
|
||||||
|
|
Loading…
Add table
Reference in a new issue