diff options
Diffstat (limited to 'src/lib/Media/Anime')
| -rw-r--r-- | src/lib/Media/Anime/Airing/classify.test.ts | 24 | ||||
| -rw-r--r-- | src/lib/Media/Anime/Airing/match.ts | 6 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/lib/Media/Anime/Airing/classify.test.ts b/src/lib/Media/Anime/Airing/classify.test.ts index eeff2036..7b3aea32 100644 --- a/src/lib/Media/Anime/Airing/classify.test.ts +++ b/src/lib/Media/Anime/Airing/classify.test.ts @@ -210,6 +210,30 @@ describe("countdown source fallback", () => { }); }); +describe("release timing", () => { + it("rolls a just-aired release forward instead of returning a past time", () => { + clearInjectAiringTimeCache(); + + const media = baseMedia(170019); + const justAired = Math.floor(Date.now() / 1000) - 3 * 60; + + media.nextAiringEpisode = { + episode: 10, + airingAt: justAired + 12 * 60 * 60, + }; + + const schedule = subScheduleFor(media, justAired); + + settings.setKey("countdownSource", "sub"); + + const injected = injectAiringTime(media, schedule); + + expect(injected.nextAiringEpisode?.airingAt).toBeGreaterThan( + Date.now() / 1000, + ); + }); +}); + describe("injectAiringTime cache safety", () => { it("does not let caller mutation poison cached injected media", () => { const media = baseMedia(444444); diff --git a/src/lib/Media/Anime/Airing/match.ts b/src/lib/Media/Anime/Airing/match.ts index 9cfe6102..1994b300 100644 --- a/src/lib/Media/Anime/Airing/match.ts +++ b/src/lib/Media/Anime/Airing/match.ts @@ -144,7 +144,9 @@ const findScheduleEntry = ( // Resolve the next future release time for a matched entry. AnimeSchedule gives // the current week's episode; a delay window or a weekly cadence rolls a past -// release forward to the next occurrence. +// release forward to the next occurrence. This must never return a past time — +// a stuck-in-the-past airingAt produces a negative countdown and a tight +// refresh loop (see scheduleAiringRefresh). const nextReleaseTime = ( entry: AiringEntry, nowEpochSeconds: number, @@ -155,7 +157,7 @@ const nextReleaseTime = ( const base = entry.airingAt; if (!base) return 0; - if (base > nowEpochSeconds - STALE_AIRING_GRACE_SECONDS) return base; + if (base > nowEpochSeconds) return base; const weeksElapsed = Math.ceil((nowEpochSeconds - base) / SEVEN_DAYS_SECONDS); |