From 6de055dc504a55d383ef836092613c456507514a Mon Sep 17 00:00:00 2001
From: Guus van Meerveld
- {video.duration}
+ {formatDuration(video.duration)}
- Views: {formatNumber(video.views)} + Views: {formatViewCount(video.views)}
diff --git a/src/utils/formatDuration.ts b/src/utils/formatDuration.ts new file mode 100644 index 0000000..388b288 --- /dev/null +++ b/src/utils/formatDuration.ts @@ -0,0 +1,9 @@ +import { Duration } from "luxon"; + +const formatDuration = (ms: number): string => { + if (ms / (60 * 60 * 1000) >= 1) + return Duration.fromMillis(ms).toFormat("HH:mm:ss"); + else return Duration.fromMillis(ms).toFormat("mm:ss"); +}; + +export default formatDuration; diff --git a/src/utils/formatNumbers.ts b/src/utils/formatViewCount.ts similarity index 81% rename from src/utils/formatNumbers.ts rename to src/utils/formatViewCount.ts index 5a486e7..036f76d 100644 --- a/src/utils/formatNumbers.ts +++ b/src/utils/formatViewCount.ts @@ -1,4 +1,4 @@ -const formatNumber = (num: number): string => { +const formatViewCount = (num: number): string => { // Nine Zeroes for Billions return Math.abs(num) >= 1.0e9 ? (Math.abs(num) / 1.0e9).toPrecision(3) + "B" @@ -11,4 +11,4 @@ const formatNumber = (num: number): string => { : Math.abs(num).toString(); }; -export default formatNumber; +export default formatViewCount; diff --git a/yarn.lock b/yarn.lock index ad3ffc6..7eddb01 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3023,6 +3023,11 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ== +"@types/luxon@^3.4.2": + version "3.4.2" + resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.4.2.tgz#e4fc7214a420173cea47739c33cdf10874694db7" + integrity sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA== + "@types/minimatch@*": version "5.1.2" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" @@ -5113,6 +5118,11 @@ lru-cache@^6.0.0: resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3" integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q== +luxon@^3.4.4: + version "3.4.4" + resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.4.4.tgz#cf20dc27dc532ba41a169c43fdcc0063601577af" + integrity sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA== + magic-string@^0.25.0, magic-string@^0.25.7: version "0.25.9" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c"