From fe95043124a09d91b5cd8da9ef9cabbe26b672ed Mon Sep 17 00:00:00 2001 From: Stephen Fraser Date: Mon, 3 Jun 2024 12:34:17 +0100 Subject: [PATCH] Fixed temporal selector parsing (2) --- __tests__/parse-selector.tests.ts | 36 +++++++++++++++++++++--- src/annotation-targets/parse-selector.ts | 2 +- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/__tests__/parse-selector.tests.ts b/__tests__/parse-selector.tests.ts index 445728f..10939c5 100644 --- a/__tests__/parse-selector.tests.ts +++ b/__tests__/parse-selector.tests.ts @@ -2002,7 +2002,7 @@ describe('parse selector', () => { "selector": { "temporal": { "endTime": undefined, - "startTime": 0.5, + "startTime": 10.5, }, "type": "TemporalSelector", }, @@ -2010,7 +2010,7 @@ describe('parse selector', () => { { "temporal": { "endTime": undefined, - "startTime": 0.5, + "startTime": 10.5, }, "type": "TemporalSelector", }, @@ -2029,7 +2029,7 @@ describe('parse selector', () => { "selector": { "temporal": { "endTime": 20.5, - "startTime": 0.5, + "startTime": 10.5, }, "type": "TemporalSelector", }, @@ -2037,7 +2037,35 @@ describe('parse selector', () => { { "temporal": { "endTime": 20.5, - "startTime": 0.5, + "startTime": 10.5, + }, + "type": "TemporalSelector", + }, + ], + } + `); + }); + + test('temporal with start offset', () => { + const selector: Selector = { + type: 'FragmentSelector', + value: 't=302.05,3971.24', + }; + + expect(parseSelector(selector)).toMatchInlineSnapshot(` + { + "selector": { + "temporal": { + "endTime": 3971.24, + "startTime": 302.05, + }, + "type": "TemporalSelector", + }, + "selectors": [ + { + "temporal": { + "endTime": 3971.24, + "startTime": 302.05, }, "type": "TemporalSelector", }, diff --git a/src/annotation-targets/parse-selector.ts b/src/annotation-targets/parse-selector.ts index b630d55..71eec5a 100644 --- a/src/annotation-targets/parse-selector.ts +++ b/src/annotation-targets/parse-selector.ts @@ -143,7 +143,7 @@ export function parseSelector( const selector: TemporalSelector = { type: 'TemporalSelector', temporal: { - startTime: matchTimeSelector[4] ? parseFloat(matchTimeSelector[4]) : 0, + startTime: matchTimeSelector[3] ? parseFloat(matchTimeSelector[3]) : 0, endTime: matchTimeSelector[6] ? parseFloat(matchTimeSelector[6]) : undefined, }, };