Skip to content

armgit / cogit

Public Imported from GitHub
0

Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.

fix(map): show dates in one shape instead of the browser's locale

Eren059861889180
diff --git a/packages/template/src/format.ts b/packages/template/src/format.ts
index 5d51b72..c773571 100644
--- a/packages/template/src/format.ts
+++ b/packages/template/src/format.ts
@@ -1,17 +1,22 @@
-/** Renders an ISO timestamp for humans; an unparseable value is shown as-is. */
+const pad = (value: number): string => String(value).padStart(2, "0");
+
+/**
+ * A full local timestamp (`2026-10-30 21:09`), in the same shape as the map's
+ * rows rather than the browser's locale; an unparseable value is shown as-is.
+ */
export function formatTime(iso: string | null): string {
if (!iso) return "—";
const date = new Date(iso);
- return Number.isNaN(date.getTime()) ? iso : date.toLocaleString();
+ if (Number.isNaN(date.getTime())) return iso;
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
-/** A compact date for tight headers; the full time belongs in a tooltip. */
+/** A compact date for tight headers (`10-30`); the full time belongs in a tooltip. */
export function formatDate(iso: string | null): string {
if (!iso) return "—";
const date = new Date(iso);
- return Number.isNaN(date.getTime())
- ? iso
- : date.toLocaleDateString(undefined, { month: "short", day: "numeric" });
+ if (Number.isNaN(date.getTime())) return iso;
+ return `${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
}
/** A compact stamp for dense rows ("10-24 00:10"); unparseable values pass through. */
@@ -19,7 +24,6 @@ export function formatStamp(iso: string | null): string {
if (!iso) return "—";
const date = new Date(iso);
if (Number.isNaN(date.getTime())) return iso;
- const pad = (value: number): string => String(value).padStart(2, "0");
return `${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
@@ -34,7 +38,6 @@ export function dayOf(iso: string | undefined): string | null {
export function formatClock(iso: string): string {
const date = new Date(iso);
if (Number.isNaN(date.getTime())) return iso;
- const pad = (value: number): string => String(value).padStart(2, "0");
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
diff --git a/packages/template/test/format.test.ts b/packages/template/test/format.test.ts
index 3a5bb00..52608ef 100644
--- a/packages/template/test/format.test.ts
+++ b/packages/template/test/format.test.ts
@@ -10,13 +10,14 @@ describe("format", () => {
});
it("renders a short date without the time of day", () => {
- const iso = "2026-10-21T10:00:00.000Z";
- const expected = new Date(iso).toLocaleDateString(undefined, {
- month: "short",
- day: "numeric",
- });
- expect(formatDate(iso)).toBe(expected);
- expect(formatDate(iso)).not.toContain(":");
+ // A local time, so the expectation does not depend on the machine's zone.
+ const iso = new Date(2026, 9, 21, 10, 0).toISOString();
+ expect(formatDate(iso)).toBe("10-21");
+ });
+
+ it("renders a full time like the map rows, not in the browser's locale", () => {
+ const iso = new Date(2026, 9, 30, 21, 9, 30).toISOString();
+ expect(formatTime(iso)).toBe("2026-10-30 21:09");
});
});