Normalize countdown keyboard adjustments and roll seconds across minutes

Co-authored-by: Shelley <shelley@exe.dev>
This commit is contained in:
Leon Mika 2026-10-10 06:50:45 +00:00
parent 9c993beda8
commit ebfd6e4ce1
3 changed files with 48 additions and 4 deletions

View file

@ -10,6 +10,16 @@ export function splitSeconds(seconds) {
};
}
export function adjustTime(minutes, seconds, field, delta) {
const total = integer(minutes) * 60n + integer(seconds);
if (field === 'minutes') {
const adjusted = total / 60n + delta;
return splitSeconds((adjusted < 0n ? 0n : adjusted) * 60n + total % 60n);
}
const adjusted = total + delta;
return splitSeconds(adjusted < 0n ? 0n : adjusted);
}
export class Countdown {
constructor(now = Date.now) {
this.now = now;