From 418ce0465e551a4f85e2eb12783a0ac551a94efd Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 20 Apr 2024 04:48:37 -0700 Subject: fix(AiringTime): add hours to weeks and days --- src/lib/Media/Anime/Airing/AiringTime.svelte | 29 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/lib/Media/Anime/Airing/AiringTime.svelte b/src/lib/Media/Anime/Airing/AiringTime.svelte index 57e016da..f4512d4c 100644 --- a/src/lib/Media/Anime/Airing/AiringTime.svelte +++ b/src/lib/Media/Anime/Airing/AiringTime.svelte @@ -63,29 +63,34 @@ hours = minutes / 60; if (hours > 24) { - let weeks = Math.floor(hours / 24) / 7; + const days = Math.floor(hours / 24); + const weeks = Math.floor(days / 7); few = false; if (weeks >= 1.5) { - weeks = Math.round(weeks); - timeFrame = `${weeks}${shortenCountdown ? 'w' : ' week'}${ weeks === 1 || shortenCountdown ? '' : 's' }`; - } else { - const days = Math.round(Math.floor(hours / 24)); - const residualHours = Math.floor(hours - days * 24); - timeFrame += `${days.toFixed(0)}${shortenCountdown ? 'd' : ' day'}${ + const residualDays = days % 7; + + if (residualDays > 0) + timeFrame += `${shortenCountdown ? '' : ' '}${residualDays}${ + shortenCountdown ? 'd' : ' day' + }${residualDays === 1 || shortenCountdown ? '' : 's'}`; + } else { + timeFrame += `${days}${shortenCountdown ? 'd' : ' day'}${ days === 1 || shortenCountdown ? '' : 's' }`; - - if (residualHours > 0) - timeFrame += `${shortenCountdown ? '' : ' '}${residualHours}${ - shortenCountdown ? 'h' : ' hour' - }${residualHours === 1 || shortenCountdown ? '' : 's'}`; } + + const residualHours = Math.floor(hours - days * 24); + + if (residualHours > 0) + timeFrame += `${shortenCountdown ? '' : ' '}${residualHours}${ + shortenCountdown ? 'h' : ' hour' + }${residualHours === 1 || shortenCountdown ? '' : 's'}`; } else { const residualMinutes = Math.round(minutes - Math.floor(hours) * 60); -- cgit v1.2.3