From 050f4ffb923cfed1265d688a53b64cd820c2fef6 Mon Sep 17 00:00:00 2001 From: Cyril Lashkevich Date: Tue, 3 Oct 2023 04:37:48 +0200 Subject: [PATCH] Fixed rounding issue with timestamps like X.999 (#16) --- src/stringifier.js | 3 ++- test/stringifier.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/stringifier.js b/src/stringifier.js index ed53440..33224ce 100644 --- a/src/stringifier.js +++ b/src/stringifier.js @@ -8,7 +8,8 @@ function pad00(n) { return `00${n}`.slice(-2); } -export function stringifyTime(t) { +export function stringifyTime(tf) { + const t = Number.parseFloat(tf.toFixed(2)); const ms = t.toFixed(2).slice(-2); const s = (t | 0) % 60; const m = (t / 60 | 0) % 60; diff --git a/test/stringifier.js b/test/stringifier.js index 0a5465c..7df2d16 100644 --- a/test/stringifier.js +++ b/test/stringifier.js @@ -15,6 +15,7 @@ import { describe('ASS stringifier', () => { it('should stringify time', () => { expect(stringifyTime(0)).to.equal('0:00:00.00'); + expect(stringifyTime(15.999)).to.equal('0:00:16.00'); expect(stringifyTime(5025.67)).to.equal('1:23:45.67'); });