fix/58-countdown

correct issues on countdown clock (#68)
This commit is contained in:
Carlos Valente
2021-12-16 22:13:41 +01:00
committed by GitHub
parent cd911aaaa2
commit 2751ed3d33
2 changed files with 28 additions and 2 deletions
+3 -1
View File
@@ -67,7 +67,9 @@ export class Timer {
// helpers
static toSeconds(millis) {
if (millis == null) return null;
return Math.floor(Math.max(millis * 0.001), 0);
return Math.ceil(millis * 0.001);
}
// get current time in epoc
+25 -1
View File
@@ -17,4 +17,28 @@ test('object instantiates correctly', () => {
expect(t._pausedInterval).toBeNull;
expect(t._pausedTotal).toBeNull;
expect(t.state).toBe('stop');
})
});
test('convert between mills and seconds correctly', () => {
expect(Timer.toSeconds(10000)).toBe(10);
expect(Timer.toSeconds(9016)).toBe(10);
expect(Timer.toSeconds(8016)).toBe(9);
expect(Timer.toSeconds(7010)).toBe(8);
expect(Timer.toSeconds(6006)).toBe(7);
expect(Timer.toSeconds(4999)).toBe(5);
expect(Timer.toSeconds(2995)).toBe(3);
expect(Timer.toSeconds(1991)).toBe(2);
expect(Timer.toSeconds(992)).toBe(1);
expect(Timer.toSeconds(127)).toBe(1);
expect(Timer.toSeconds(0)).toBe(0);
expect(Timer.toSeconds(-0)).toBe(-0);
expect(Timer.toSeconds(-127)).toBe(-0);
expect(Timer.toSeconds(-992)).toBe(-0);
expect(Timer.toSeconds(-1991)).toBe(-1);
expect(Timer.toSeconds(-2995)).toBe(-2);
expect(Timer.toSeconds(-4999)).toBe(-4);
expect(Timer.toSeconds(-6006)).toBe(-6);
expect(Timer.toSeconds(-7010)).toBe(-7);
expect(Timer.toSeconds(-8016)).toBe(-8);
expect(Timer.toSeconds(-10000)).toBe(-10);
});