fix(profile): time untill streak is available calculated incorrectly (L-E-Freeman, Miodec)

Closes #4735
This commit is contained in:
Miodec 2024-01-18 23:05:49 +01:00
parent 32bc5f8f42
commit e958803dd2
2 changed files with 9 additions and 6 deletions

View file

@ -130,8 +130,9 @@ export async function update(
const lastResult = results?.[0];
const dayInMilis = 1000 * 60 * 60 * 24;
const milisOffset = (profile.streakHourOffset ?? 0) * 3600000;
let target = Misc.getCurrentDayTimestamp() + dayInMilis + milisOffset;
let target =
Misc.getCurrentDayTimestamp(profile.streakHourOffset) + dayInMilis;
if (target < Date.now()) {
target += dayInMilis;
}
@ -140,10 +141,11 @@ export async function update(
console.debug("Streak hour offset");
console.debug("date.now()", Date.now(), new Date(Date.now()));
console.debug("dayInMilis", dayInMilis);
console.debug("milisOffset", milisOffset);
console.debug(
"difTarget",
new Date(Misc.getCurrentDayTimestamp() + dayInMilis + milisOffset)
new Date(
Misc.getCurrentDayTimestamp(profile.streakHourOffset) + dayInMilis
)
);
console.debug("timeDif", timeDif);
console.debug(

View file

@ -1516,9 +1516,10 @@ export async function checkIfLanguageSupportsZipf(
return "unknown";
}
export function getCurrentDayTimestamp(): number {
export function getCurrentDayTimestamp(hourOffset = 0): number {
const offsetMilis = hourOffset * MILISECONDS_IN_HOUR;
const currentTime = Date.now();
return getStartOfDayTimestamp(currentTime);
return getStartOfDayTimestamp(currentTime, offsetMilis);
}
const MILISECONDS_IN_HOUR = 3600000;