Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ module.exports = function (opts) {
const offsetMs = opts.offsetMs || 0

const TIME_FORMAT = 'HH:mm:ss.SSS'
const TIME_FORMAT_SHORT = 'mm:ss.SSS'
const TIME_SEPARATOR = ' --> '

function parseTimes (line) {
return line.split(TIME_SEPARATOR)
.map(timeString => moment(timeString.trim(), TIME_FORMAT))
.map(timeString => moment(timeString.trim(), getTimeFormat(timeString)))
}

function shiftTimeLine (line, offsetMs) {
Expand All @@ -22,6 +23,12 @@ module.exports = function (opts) {
.join(TIME_SEPARATOR)
}

function getTimeFormat (timestring) {
//hours on VTT files are optional
//if the lenth of the timestring is less 9 characters or less, assume it's short, otherwise the standard
return timestring.trim().length <= 9 ? TIME_FORMAT_SHORT : TIME_FORMAT
}

function isTimeLine (line) {
return line.indexOf(TIME_SEPARATOR) > -1
}
Expand Down