Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/story-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ export const DEADLINE_MS = DEADLINE_HOURS * 60 * 60 * 1000;

export type StoryStatus = "active" | "completed" | "expired";

/** Determine whether a story is active, completed, or expired. */
/**
* Determine whether a story is active, completed, or expired.
*
* All stories have a 7-day deadline from their last plot — the `has_deadline`
* DB field is unreliable for older stories indexed before the flag existed.
* We check deadline expiry for any story with a `last_plot_time`, regardless
* of `has_deadline`.
*/
export function getStoryStatus(storyline: Pick<Storyline, "sunset" | "has_deadline" | "last_plot_time">): StoryStatus {
if (storyline.sunset) return "completed";
if (storyline.has_deadline && storyline.last_plot_time) {
if (storyline.last_plot_time) {
const deadline = new Date(storyline.last_plot_time).getTime() + DEADLINE_MS;
if (Date.now() > deadline) return "expired";
}
Expand Down
Loading
Loading