diff --git a/site/src/lib/format.ts b/site/src/lib/format.ts index cb45676..10ce83d 100644 --- a/site/src/lib/format.ts +++ b/site/src/lib/format.ts @@ -12,6 +12,19 @@ export const compact = (n: number) => ? `${+(n / 1000).toFixed(n < 1e4 ? 1 : 0)}k` : `${+(n / 1e6).toFixed(1)}m`; +// Display-only: data and scripts stay UTC. Short zone name gives CST or CDT. +export const centralStamp = (d: Date) => + new Intl.DateTimeFormat("en-US", { + timeZone: "America/Chicago", + month: "short", + day: "numeric", + hour: "numeric", + minute: "2-digit", + timeZoneName: "short", + }) + .format(d) + .replace(" at ", ", "); + const UNITS: [number, string][] = [ [365 * 86400, "year"], [30 * 86400, "month"], diff --git a/site/src/pages/index.astro b/site/src/pages/index.astro index 774b7a5..449f00d 100644 --- a/site/src/pages/index.astro +++ b/site/src/pages/index.astro @@ -3,13 +3,13 @@ import Base from "../layouts/Base.astro"; import Leaderboard from "../components/Leaderboard.astro"; import Explain from "../components/Explain.astro"; import { loadAll, liveList, trending } from "../lib/data.ts"; -import { icon, num } from "../lib/format.ts"; +import { centralStamp, icon, num } from "../lib/format.ts"; const { entries, categories } = loadAll(); const live = liveList(entries); const climber = trending(entries)[0]; const built = new Date(); -const stamp = built.toLocaleString("en-GB", { day: "numeric", month: "short", hour: "2-digit", minute: "2-digit", timeZone: "UTC" }); +const stamp = centralStamp(built); ---

- Updated live Last count + Updated live Last count

Top GitHub Repos, ranked by developers

Stars pile up for years. A Like here is one developer saying they'd use it today, so the order moves every hour.

diff --git a/site/tests/format.test.mjs b/site/tests/format.test.mjs new file mode 100644 index 0000000..17f7d15 --- /dev/null +++ b/site/tests/format.test.mjs @@ -0,0 +1,17 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { centralStamp } from "../src/lib/format.ts"; + +test("centralStamp shows CST in winter", () => { + assert.equal( + centralStamp(new Date("2026-11-06T03:48:00Z")), + "Nov 5, 9:48 PM CST", + ); +}); + +test("centralStamp shows CDT in summer", () => { + assert.equal( + centralStamp(new Date("2026-07-01T17:00:00Z")), + "Jul 1, 12:00 PM CDT", + ); +});