From 4c2a598be4dba84e146e47adfa89c6e28514d097 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 28 May 2021 19:34:25 +1000 Subject: [PATCH] round to whole seconds the steps are serialized as f32, and the resulting imprecision was leading to decimal values closes #1203 --- ts/deckoptions/steps.test.ts | 6 ++++++ ts/deckoptions/steps.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ts/deckoptions/steps.test.ts b/ts/deckoptions/steps.test.ts index 9bc33eaba..bd7b82025 100644 --- a/ts/deckoptions/steps.test.ts +++ b/ts/deckoptions/steps.test.ts @@ -9,6 +9,7 @@ test("whole steps", () => { expect(stepsToString(steps)).toBe(string); expect(stringToSteps(string)).toStrictEqual(steps); }); + test("fractional steps", () => { const steps = [1 / 60, 5 / 60, 1.5, 400]; const string = "1s 5s 90s 400m"; @@ -16,6 +17,11 @@ test("fractional steps", () => { expect(stringToSteps(string)).toStrictEqual(steps); }); +test("rounding", () => { + const steps = [0.1666666716337204]; + expect(stepsToString(steps)).toBe("10s"); +}); + test("parsing", () => { expect(stringToSteps("")).toStrictEqual([]); expect(stringToSteps(" ")).toStrictEqual([]); diff --git a/ts/deckoptions/steps.ts b/ts/deckoptions/steps.ts index 856ecbc87..36a3c1757 100644 --- a/ts/deckoptions/steps.ts +++ b/ts/deckoptions/steps.ts @@ -38,7 +38,7 @@ function minutesToString(step: number): string { if ([TimespanUnit.Months, TimespanUnit.Years].includes(unit)) { unit = TimespanUnit.Days; } - const amount = unitAmount(unit, secs); + const amount = Math.round(unitAmount(unit, secs)); return `${amount}${unitSuffix(unit)}`; }