Skip to content

Commit 8aa1f51

Browse files
committed
fix: wpm sometimes goes negative in zen mode
kind of a band aid fix but its ok closes monkeytypegame#7099
1 parent 33880b3 commit 8aa1f51

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

frontend/src/ts/test/test-stats.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,18 @@ export function setInvalid(): void {
138138
}
139139

140140
export function calculateTestSeconds(now?: number): number {
141-
if (now === undefined) {
142-
return (end - start) / 1000;
143-
} else {
144-
return (now - start) / 1000;
141+
let duration = (end - start) / 1000;
142+
143+
if (now !== undefined) {
144+
duration = (now - start) / 1000;
145+
}
146+
147+
if (Config.mode === "zen" && duration < 0) {
148+
duration = 0;
149+
console.log("Zen mode with negative duration detected, setting to 0");
145150
}
151+
152+
return duration;
146153
}
147154

148155
export function calculateWpmAndRaw(

0 commit comments

Comments
 (0)