diff --git a/src/__tests__/timer.test.ts b/src/__tests__/timer.test.ts index bc7cfb2..fac4647 100644 --- a/src/__tests__/timer.test.ts +++ b/src/__tests__/timer.test.ts @@ -37,3 +37,12 @@ test('Negative time zeroed', () => { expect(timer.display()).toBe('0:00'); expect(timer.flagged()).toBeTrue(); }); + +test('No increment after flagging', () => { + const timer = new FischerTimer(10000, 20000, 1000); + timer.begin(); + timer.remaining = 0; + expect(timer.end()).toBeTrue(); + expect(timer.display()).toBe('0:00'); + expect(timer.flagged()).toBeTrue(); +}); diff --git a/src/timer.ts b/src/timer.ts index f6fb124..f31e7f4 100644 --- a/src/timer.ts +++ b/src/timer.ts @@ -47,11 +47,15 @@ export class FischerTimer { } const delta = performance.now() - this.reference; this.reference = null; - const flagged = delta > this.remaining; - this.remaining = Math.min( - this.maximum, - this.remaining - delta + this.increment - ); + const flagged = delta >= this.remaining; + if (flagged) { + this.remaining = 0; + } else { + this.remaining = Math.min( + this.maximum, + this.remaining - delta + this.increment + ); + } return flagged; } @@ -74,6 +78,6 @@ export class FischerTimer { } flagged(): boolean { - return this.timeRemaining() < 0; + return this.timeRemaining() <= 0; } }