Normalize countdown keyboard adjustments and roll seconds across minutes
Co-authored-by: Shelley <shelley@exe.dev>
This commit is contained in:
parent
9c993beda8
commit
ebfd6e4ce1
3 changed files with 48 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue