From 4dc1995c334688663e9aa7a744e982026d3ffe8d Mon Sep 17 00:00:00 2001 From: EliteAsian <29520859+EliteAsian123@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:48:58 -0400 Subject: [PATCH] Can't use `pretty-ms` so use `humanizeDuration` instead --- package-lock.json | 65 +++++++++++++++-------------------------- package.json | 3 +- src/utils/timeFormat.ts | 26 +++++++++++++---- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index b85732f..5093672 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "yet_another_launcher", - "version": "0.3.2", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "yet_another_launcher", - "version": "0.3.2", + "version": "1.0.0", "dependencies": { "@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-dropdown-menu": "^2.0.6", @@ -18,16 +18,17 @@ "@tanstack/react-query": "^5.14.0", "@tanstack/react-query-persist-client": "^5.14.0", "@tauri-apps/api": "^1.5.2", + "@types/humanize-duration": "^3.27.4", "@types/lodash": "^4.14.202", "async-wait-until": "^2.0.12", "date-fns": "^2.30.0", "dompurify": "^3.0.6", "gray-matter": "^4.0.3", + "humanize-duration": "^3.32.1", "is-online": "^11.0.0", "js-video-url-parser": "^0.5.1", "lodash": "^4.17.21", "marked": "^11.1.0", - "pretty-ms": "^9.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-error-boundary": "^4.0.12", @@ -2975,6 +2976,11 @@ "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz", "integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==" }, + "node_modules/@types/humanize-duration": { + "version": "3.27.4", + "resolved": "https://registry.npmjs.org/@types/humanize-duration/-/humanize-duration-3.27.4.tgz", + "integrity": "sha512-yaf7kan2Sq0goxpbcwTQ+8E9RP6HutFBPv74T/IA/ojcHKhuKVlk2YFYyHhWZeLvZPzzLE3aatuQB4h0iqyyUA==" + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -5891,6 +5897,11 @@ "integrity": "sha512-J+FkSdyD+0mA0N+81tMotaRMfSL9SGi+xpD3T6YApKsc3bGSXJlfXri3VyFOeYkfLRQisDk1W+jIFFKBeUBbBg==", "dev": true }, + "node_modules/humanize-duration": { + "version": "3.32.1", + "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.32.1.tgz", + "integrity": "sha512-inh5wue5XdfObhu/IGEMiA1nUXigSGcaKNemcbLRKa7jXYGDZXr3LoT9pTIzq2hPEbld7w/qv9h+ikWGz8fL1g==" + }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -7198,17 +7209,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/parse-ms": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz", - "integrity": "sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/path-browserify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", @@ -7478,20 +7478,6 @@ "node": ">= 0.8" } }, - "node_modules/pretty-ms": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.1.0.tgz", - "integrity": "sha512-o1piW0n3tgKIKCwk2vpM/vOV13zjJzvP37Ioze54YlTHE06m4tjEbzg9WsKkvTuyYln2DHjo5pY4qrZGI0otpw==", - "dependencies": { - "parse-ms": "^4.0.0" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/process": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", @@ -10871,6 +10857,11 @@ "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz", "integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==" }, + "@types/humanize-duration": { + "version": "3.27.4", + "resolved": "https://registry.npmjs.org/@types/humanize-duration/-/humanize-duration-3.27.4.tgz", + "integrity": "sha512-yaf7kan2Sq0goxpbcwTQ+8E9RP6HutFBPv74T/IA/ojcHKhuKVlk2YFYyHhWZeLvZPzzLE3aatuQB4h0iqyyUA==" + }, "@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -13029,6 +13020,11 @@ "integrity": "sha512-J+FkSdyD+0mA0N+81tMotaRMfSL9SGi+xpD3T6YApKsc3bGSXJlfXri3VyFOeYkfLRQisDk1W+jIFFKBeUBbBg==", "dev": true }, + "humanize-duration": { + "version": "3.32.1", + "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.32.1.tgz", + "integrity": "sha512-inh5wue5XdfObhu/IGEMiA1nUXigSGcaKNemcbLRKa7jXYGDZXr3LoT9pTIzq2hPEbld7w/qv9h+ikWGz8fL1g==" + }, "ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -13964,11 +13960,6 @@ "lines-and-columns": "^1.1.6" } }, - "parse-ms": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz", - "integrity": "sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==" - }, "path-browserify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", @@ -14134,14 +14125,6 @@ "integrity": "sha512-66hKPCr+72mlfiSjlEB1+45IjXSqvVAIy6mocupoww4tBFE9R9IhwwUGoI4G++Tc9Aq+2rxOt0RFU6gPcrte0A==", "dev": true }, - "pretty-ms": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.1.0.tgz", - "integrity": "sha512-o1piW0n3tgKIKCwk2vpM/vOV13zjJzvP37Ioze54YlTHE06m4tjEbzg9WsKkvTuyYln2DHjo5pY4qrZGI0otpw==", - "requires": { - "parse-ms": "^4.0.0" - } - }, "process": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", diff --git a/package.json b/package.json index 2359e9d..0fec7d1 100644 --- a/package.json +++ b/package.json @@ -49,16 +49,17 @@ "@tanstack/react-query": "^5.14.0", "@tanstack/react-query-persist-client": "^5.14.0", "@tauri-apps/api": "^1.5.2", + "@types/humanize-duration": "^3.27.4", "@types/lodash": "^4.14.202", "async-wait-until": "^2.0.12", "date-fns": "^2.30.0", "dompurify": "^3.0.6", "gray-matter": "^4.0.3", + "humanize-duration": "^3.32.1", "is-online": "^11.0.0", "js-video-url-parser": "^0.5.1", "lodash": "^4.17.21", "marked": "^11.1.0", - "pretty-ms": "^9.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-error-boundary": "^4.0.12", diff --git a/src/utils/timeFormat.ts b/src/utils/timeFormat.ts index e733e1e..e1abffa 100644 --- a/src/utils/timeFormat.ts +++ b/src/utils/timeFormat.ts @@ -1,11 +1,27 @@ import { intlFormatDistance } from "date-fns"; -import prettyMilliseconds from "pretty-ms"; +import humanizeDuration from "humanize-duration"; export const millisToDisplayLength = (length: number, long = false) => { - return prettyMilliseconds(length, { - colonNotation: !long, - secondsDecimalDigits: 0, - }); + if (long) { + return humanizeDuration(length, { + round: true + }); + } else { + const totalSeconds = Math.round(length / 1000); + const totalMinutes = Math.floor(totalSeconds / 60); + + const seconds = totalSeconds % 60; + const minutes = totalMinutes % 60; + const hours = Math.floor(totalMinutes / 60); + + const secondsStr = seconds.toString().padStart(2, "0"); + + if (hours === 0) { + return `${minutes}:${secondsStr}`; + } else { + return `${hours}:${minutes}:${secondsStr}`; + } + } }; export const isConsideredNewRelease = (releaseDate: string, newestInSetlist: string) => {