From ba69043f90ec0b50e2132e6e47fccb0452740b89 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 6549149..dab47f0 100644 --- a/src/stringifier.js +++ b/src/stringifier.js @@ -6,7 +6,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 df2f9c1..3284b3b 100644 --- a/test/stringifier.js +++ b/test/stringifier.js @@ -6,6 +6,7 @@ import { parsed, stringified, parsed2, stringified2 } from './fixtures/stringifi 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'); });