From 14836d25bc582f5d289af3a92b96ddead02d6bfb Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 16 Dec 2023 18:55:34 -0800 Subject: fix(anime): adjust airing exact time --- src/lib/Media/anime.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/lib/Media/anime.ts') diff --git a/src/lib/Media/anime.ts b/src/lib/Media/anime.ts index b9227562..4ad23f56 100644 --- a/src/lib/Media/anime.ts +++ b/src/lib/Media/anime.ts @@ -74,6 +74,11 @@ const findClosestMatch = (times: Time[], titles: string[]) => { export const airingTime = (anime: Media, subsPlease: SubsPlease, upcoming = false) => { const airingAt = anime.nextAiringEpisode?.airingAt; let untilAiring; + let time = new Date(airingAt ? airingAt * 1000 : 0).toLocaleTimeString([], { + hour12: !settings.get().display24HourTime, + hour: 'numeric', + minute: '2-digit' + }); if (get(settings).displayNativeCountdown) { untilAiring = airingAt ? Math.round((airingAt - Date.now() / 1000) * 100) / 100 : undefined; @@ -92,23 +97,24 @@ export const airingTime = (anime: Media, subsPlease: SubsPlease, upcoming = fals } } - const time: Time | null = findClosestMatch(times, [ + const foundTime: Time | null = findClosestMatch(times, [ anime.title.romaji, anime.title.english, ...anime.synonyms ]); - if (time) untilAiring = secondsUntil((time as Time).time, (time as Time).day); - else + if (foundTime) { + untilAiring = secondsUntil((foundTime as Time).time, (foundTime as Time).day); + time = new Date(Date.now() + untilAiring * 1000).toLocaleTimeString([], { + hour12: !settings.get().display24HourTime, + hour: 'numeric', + minute: '2-digit' + }); + } else untilAiring = airingAt ? Math.round((airingAt - Date.now() / 1000) * 100) / 100 : undefined; } let timeFrame; - const time = new Date(airingAt ? airingAt * 1000 : 0).toLocaleTimeString([], { - hour12: !settings.get().display24HourTime, - hour: 'numeric', - minute: '2-digit' - }); let hours = null; if ( -- cgit v1.2.3