From 2c4af55985fcd1f401dadfbf154339dd6ebb1d7c Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Sat, 27 Jan 2024 11:17:30 +0100 Subject: [PATCH] Fix youtube timestamps larger than one hour --- package.json | 1 + src/index.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3d1d136..6831311 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "test": "mocha", "build": "esbuild src/browser.ts --bundle --minify --sourcemap --target=firefox120 --outfile=public/bundle.js", + "watch": "npm run build -- --watch", "prepare": "npm run build", "clean-coverage": "rm -rf coverage .nyc_output .xunit", "coverage": "npm run clean-coverage && nyc mocha", diff --git a/src/index.ts b/src/index.ts index 978ae1d..d49b709 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,9 +35,15 @@ function parseTimestamp(s: string): number { function toTimestamp(n: number): string { n = Math.floor(n); - return `${Math.floor(n / 60) - .toString() - .padStart(2, "0")}:${(n % 60).toString().padStart(2, "0")}`; + let result: number[] = []; + while (n / 60 > 0) { + result.push(n % 60); + n = Math.floor(n / 60); + } + return result + .map((n, i) => (i >= 2 ? n.toString() : n.toString().padStart(2, "0"))) + .reverse() + .join(":"); } export function parse_youtube(content: string): Timestamp[] {