Skip to content

Commit

Permalink
Fix: .ass does not want 3 decimals in ms
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Oct 4, 2018
1 parent ac87118 commit c4a932c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
10 changes: 4 additions & 6 deletions lib/mstime.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ var msTime = module.exports = function (val, leadingZeros) {
return res
})

var ms = val.toString()
if (ms.length < 3) {
for (var i = 0, l = ms.length; i <= leadingZeros - l; i += 1) {
ms = '0' + ms
}
var ms = Math.floor(val / 10).toString()
for (var i = 0, l = ms.length; i <= leadingZeros - l; i += 1) {
ms = '0' + ms
}

return time.join(':') + ',' + ms
}

msTime.substation = function (val) {
var time = msTime(val, true)
var time = msTime(val, 1)
return time.replace(',', '.').slice(1)
}
23 changes: 16 additions & 7 deletions test/substation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ var substation = require('../lib/substation')
suite('substation', function () {
suite('stringify', function () {
test('single', function () {
var subtitle = {
id: 1,
startTime: 1000,
endTime: 3000,
text: 'Hello World'
}
var subtitles = [
{
id: 1,
startTime: 1000,
endTime: 3000,
text: 'Hello World'
},
{
id: 2,
startTime: 4123,
endTime: 5555,
text: 'Hello World 2'
}
]

var params = {
Fontname: 'Verdana',
Fontsize: '28',
PrimaryColour: '11861244'
}

var lines = substation.stringify([ subtitle ], params).split('\n')
var lines = substation.stringify(subtitles, params).split('\n')
lines.pop()

expect(lines.shift()).to.be.equal('[Script Info]')
expect(lines.shift()).to.be.equal('Title: Videoshow video')
expect(lines.shift()).to.be.equal('ScriptType: v4')
expect(lines.pop()).to.be.equal('Dialogue: Marked=0,0:00:04.12,0:00:05.55,DefaultVCD,NTP,0000,0000,0000,,Hello World 2')
expect(lines.pop()).to.be.equal('Dialogue: Marked=0,0:00:01.00,0:00:03.00,DefaultVCD,NTP,0000,0000,0000,,Hello World')
expect(lines.pop()).to.be.equal('Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text')
})
Expand Down

0 comments on commit c4a932c

Please sign in to comment.