From 525f9d0b74464e8e993571b1fcd4bf6c87a03d33 Mon Sep 17 00:00:00 2001 From: Jip Fr Date: Fri, 26 May 2023 00:38:51 +0200 Subject: [PATCH] chore(player): revert timeArr order for improved readability --- .../controllers/ProgressListenerController.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/video/components/controllers/ProgressListenerController.tsx b/src/video/components/controllers/ProgressListenerController.tsx index 257b44ac..68cf8fc3 100644 --- a/src/video/components/controllers/ProgressListenerController.tsx +++ b/src/video/components/controllers/ProgressListenerController.tsx @@ -62,15 +62,13 @@ export function ProgressListenerController(props: Props) { lastStateProviderId.current = stateProviderId; if ((queryParams.t ?? null) !== null) { - // Convert `t` param to time. Supports only seconds, but also `3:30` or `1:30:02` - const timeArr = queryParams.t.toString().split(":").map(Number); + // Convert `t` param to time. Supports having only seconds (like `?t=192`), but also `3:30` or `1:30:02` - const hours = timeArr[timeArr.length - 3] ?? 0; - const minutes = Math.min(timeArr[timeArr.length - 2] ?? 0, 59); - const seconds = Math.min( - timeArr[timeArr.length - 1] ?? 0, - minutes > 0 ? 59 : Infinity - ); + const timeArr = queryParams.t.toString().split(":").map(Number).reverse(); // This is an array of [seconds, ?minutes, ?hours] as ints. + + const hours = timeArr[2] ?? 0; + const minutes = Math.min(timeArr[1] ?? 0, 59); + const seconds = Math.min(timeArr[0] ?? 0, minutes > 0 ? 59 : Infinity); const timeInSeconds = hours * 60 * 60 + minutes * 60 + seconds;