From 1ed136e637e5b1c9632e11cb8b0afedf79f697ea Mon Sep 17 00:00:00 2001 From: qdust41 Date: Sat, 4 Apr 2026 12:29:54 -0400 Subject: [PATCH] fixed tweet time display to show when the tweet was actually posted --- assets/js/index.tsx | 18 +++++++++++++++--- .../controllers/page_controller_test.exs | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/assets/js/index.tsx b/assets/js/index.tsx index 44ade17..088485e 100644 --- a/assets/js/index.tsx +++ b/assets/js/index.tsx @@ -55,8 +55,20 @@ const AuthCtx = createContext({ email: "", userId: "" }); // ── Helpers ──────────────────────────────────────────────────────────────────── -function timeAgo(): string { - return "just now"; +function timeAgo(insertedAt?: string | null): string { + if (!insertedAt) return "just now"; + const now = Date.now(); + const then = new Date(insertedAt).getTime(); + const diffSec = Math.floor((now - then) / 1000); + if (diffSec < 5) return "just now"; + if (diffSec < 60) return `${diffSec}s`; + const diffMin = Math.floor(diffSec / 60); + if (diffMin < 60) return `${diffMin}m`; + const diffHr = Math.floor(diffMin / 60); + if (diffHr < 24) return `${diffHr}h`; + const diffDay = Math.floor(diffHr / 24); + if (diffDay < 7) return `${diffDay}d`; + return new Date(insertedAt).toLocaleDateString(undefined, { month: "short", day: "numeric" }); } function getAssetHost(): string { @@ -501,7 +513,7 @@ function TweetCard({ tweet }: { tweet: Tweet }) {
{tweet.userEmail ?? "@mixer"} · - {timeAgo()} + {timeAgo(tweet.insertedAt)} {canModify && (