diff --git a/index.js b/index.js index 5f72b04..6fa1524 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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 }