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
13 changes: 13 additions & 0 deletions site/src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 3 additions & 3 deletions site/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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);
---

<Base
Expand All @@ -20,7 +20,7 @@ const stamp = built.toLocaleString("en-GB", { day: "numeric", month: "short", ho
<div class="wrap hero-grid">
<div>
<p class="live">
<span class="pulse" aria-hidden="true"></span><strong>Updated live</strong> Last count <time datetime={built.toISOString()}>{stamp} UTC</time>
<span class="pulse" aria-hidden="true"></span><strong>Updated live</strong> Last count <time datetime={built.toISOString()}>{stamp}</time>
</p>
<h1>Top GitHub Repos, ranked by developers</h1>
<p>Stars pile up for years. A Like here is one developer saying they'd use it today, so the order moves every hour.</p>
Expand Down
17 changes: 17 additions & 0 deletions site/tests/format.test.mjs
Original file line number Diff line number Diff line change
@@ -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",
);
});
Loading