Skip to content

Commit

Permalink
Fixed rounding issue with timestamps like X.999 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
notorca authored Oct 3, 2023
1 parent ea5505c commit ba69043
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 @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down

0 comments on commit ba69043

Please sign in to comment.