Skip to content

Commit

Permalink
Fixed rounding issue with timestamps like X.999 (weizhenye#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
notorca authored and widatama committed Aug 19, 2024
1 parent 2d6fcfa commit 050f4ff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down

0 comments on commit 050f4ff

Please sign in to comment.