Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow timestamps of srt and vtt files with a 1-digit hour #45

Merged
merged 2 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions dist/subtitle.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function toMS(timestamp) {
return timestamp;
}

var match = timestamp.match(/^(?:(\d{2,}):)?(\d{2}):(\d{2})[,.](\d{3})$/);
var match = timestamp.match(/^(?:(\d{1,}):)?(\d{2}):(\d{2})[,.](\d{3})$/);

if (!match) {
throw new Error('Invalid SRT or VTT time format: "' + timestamp + '"');
Expand Down Expand Up @@ -238,7 +238,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* @type {RegExp}
*/

var RE = /^((?:\d{2,}:)?\d{2}:\d{2}[,.]\d{3}) --> ((?:\d{2,}:)?\d{2}:\d{2}[,.]\d{3})(?: (.*))?$/;
var RE = /^((?:\d{1,}:)?\d{2}:\d{2}[,.]\d{3}) --> ((?:\d{1,}:)?\d{2}:\d{2}[,.]\d{3})(?: (.*))?$/;

/**
* parseTimestamps
Expand Down
2 changes: 1 addition & 1 deletion lib/parseTimestamps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import toMS from './toMS'
* @type {RegExp}
*/

const RE = /^((?:\d{2,}:)?\d{2}:\d{2}[,.]\d{3}) --> ((?:\d{2,}:)?\d{2}:\d{2}[,.]\d{3})(?: (.*))?$/
const RE = /^((?:\d{1,}:)?\d{2}:\d{2}[,.]\d{3}) --> ((?:\d{1,}:)?\d{2}:\d{2}[,.]\d{3})(?: (.*))?$/

/**
* parseTimestamps
Expand Down
2 changes: 1 addition & 1 deletion lib/toMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function toMS (timestamp) {
return timestamp
}

const match = timestamp.match(/^(?:(\d{2,}):)?(\d{2}):(\d{2})[,.](\d{3})$/)
const match = timestamp.match(/^(?:(\d{1,}):)?(\d{2}):(\d{2})[,.](\d{3})$/)

if (!match) {
throw new Error('Invalid SRT or VTT time format: "' + timestamp + '"')
Expand Down
21 changes: 21 additions & 0 deletions test/parseTimestamps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ test('parseTimestamps with SRT input', t => {
start: 45296789,
end: 357414321
})

check('0:59:50,050 --> 1:00:20,070', {
start: 3590050,
end: 3620070
})

check('0:00:20,000 --> 0:00:24,400', {
start: 20000,
end: 24400
})
})

test('parseTimestamps with VTT input and short formats', t => {
Expand All @@ -47,6 +57,11 @@ test('parseTimestamps with VTT input and short formats', t => {
start: 3590050,
end: 3620070
})

check('0:59:50.050 --> 1:00:20.070', {
start: 3590050,
end: 3620070
})
})

test('parseTimestamps with VTT settings', t => {
Expand All @@ -63,4 +78,10 @@ test('parseTimestamps with VTT settings', t => {
end: 24400,
settings: 'position:45%,line-right align:center size:35%'
})

check('0:00:20.000 --> 0:00:24.400 position:45%,line-right align:center size:35%', {
start: 20000,
end: 24400,
settings: 'position:45%,line-right align:center size:35%'
})
})