fix timframe changes showing 0 for some things
All checks were successful
Deploy Backend / deploy (push) Successful in 3m3s
Deploy Website / deploy (push) Successful in 4m54s

This commit is contained in:
Lee 2024-10-11 21:45:50 +01:00
parent 6ae69c2fec
commit 786bc69cf3

@ -167,7 +167,31 @@ export async function getScoreSaberPlayerFromToken(
*/
const getChange = (statType: "rank" | "countryRank" | "pp", daysAgo: number = 1): number => {
const todayStats = statisticHistory[todayDate];
const otherDate = formatDateMinimal(getMidnightAlignedDate(getDaysAgoDate(daysAgo)));
let otherDate: string | undefined;
// Yesterday
if (daysAgo == 1) {
otherDate = todayDate;
} else {
// get the closest next date
let closestDateDiff = Infinity;
for (const dateKey in statisticHistory) {
const date = new Date(dateKey);
const daysDiff = Math.abs(date.getTime() - getDaysAgoDate(daysAgo).getTime());
// If this date is closer, update the closest date
if (daysDiff < closestDateDiff) {
closestDateDiff = daysDiff;
otherDate = formatDateMinimal(date);
}
}
}
if (!otherDate) {
return 0;
}
const otherStats = statisticHistory[otherDate];
const hasChange = !!(todayStats && otherStats);