Public: anyone can read this; the crew can change it.

A date from another year says its year on the clock's Closed list, the deal page's "All done" line and the terminal's closed list #239

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/206-a-date-from-another-year-says-its-year-o → main 3 commits fork 2 threads · 2 unresolved

  • Merged. mason/206-a-date-from-another-year-says-its-year-o was merged into main as f617d15.

Review

Sign in to review this change.
8 files changed +76 −8
src/dates.test.ts +12
@@ -12,6 +12,8 @@ import {
1212 isHoliday,
1313 nextBusinessDay,
1414 relative,
15 spoken,
16 today,
1517 urgency,
1618 } from "./dates.ts";
1719 import { DEFAULT_LENGTHS, schedule } from "./deadlines.ts";
@@ -143,3 +145,13 @@ test("business days step over a holiday; calendar days do not", () => {
143145 expect(addBusinessDays("2026-11-27", -1)).toBe("2026-11-25");
144146 expect(addDays("2026-11-25", 1)).toBe("2026-11-26");
145147 });
148
149 test("spoken names the year only when told today and the date is in another year", () => {
150 expect(spoken("2025-11-09")).toBe("Sun, Nov 9");
151 expect(spoken("2025-11-09", "2026-11-08")).toBe("Sun, Nov 9, 2025");
152 expect(spoken("2026-11-09", "2026-11-08")).toBe("Mon, Nov 9");
153 // Across New Year in the agent's own zone: 05:00Z on Jan 1 is still Dec 31 in Los Angeles.
154 const instant = new Date("2027-01-01T05:00:00Z");
155 expect(spoken("2026-12-31", today("America/Los_Angeles", instant))).toBe("Thu, Dec 31");
156 expect(spoken("2026-12-31", today("UTC", instant))).toBe("Thu, Dec 31, 2026");
157 });
src/dates.ts +6 −2
@@ -186,8 +186,12 @@ const SHORT = new Intl.DateTimeFormat("en-US", {
186186 timeZone: "UTC",
187187 });
188188
189 /** "Fri, Oct 16" — how a person reads a date in a sentence. */
190 export const spoken = (date: string): string => SPOKEN.format(toMs(date));
189 /**
190 * "Fri, Oct 16" — how a person reads a date in a sentence. Given `on` (the agent's
191 * today), a date from another calendar year also says its year: "Sun, Nov 9, 2025".
192 */
193 export const spoken = (date: string, on?: string): string =>
194 on !== undefined && date.slice(0, 4) !== on.slice(0, 4) ? `${SPOKEN.format(toMs(date))}, ${date.slice(0, 4)}` : SPOKEN.format(toMs(date));
191195
192196 const WEEKDAY = new Intl.DateTimeFormat("en-US", { weekday: "long", timeZone: "UTC" });
193197
src/pages/clock.ts +1 −1
@@ -216,7 +216,7 @@ function render(input: {
216216 : `<section id="closed" class="card" data-live="deal.changed">
217217 <h2>Closed <span class="muted">· ${closed.length + fell.length}</span></h2>
218218 ${who.role === "anon" ? "" : `<p class="small"><a href="/deals/csv?closed=1" download>Download spreadsheet with closed deals</a></p>`}
219 <ul class="closed">${closed.map((deal) => `<li><a href="/deals/${deal.id}">${escape(deal.address)}</a> <span class="muted">closed ${escape(spoken(deal.closing))}${deal.sale_price === null ? "" : ` · ${dollars(deal.sale_price)}`}</span> ${sideLabel(deal.side)}</li>`).join("")}${fell.map((deal) => `<li><a href="/deals/${deal.id}">${escape(deal.address)}</a> <b>Fell through</b> <span class="muted">${escape(spoken(fellOn(deal)))} · ${escape(deal.fell_reason ?? "")}</span> ${sideLabel(deal.side)}</li>`).join("")}</ul>
219 <ul class="closed">${closed.map((deal) => `<li><a href="/deals/${deal.id}">${escape(deal.address)}</a> <span class="muted">closed ${escape(spoken(deal.closing, on))}${deal.sale_price === null ? "" : ` · ${dollars(deal.sale_price)}`}</span> ${sideLabel(deal.side)}</li>`).join("")}${fell.map((deal) => `<li><a href="/deals/${deal.id}">${escape(deal.address)}</a> <b>Fell through</b> <span class="muted">${escape(spoken(fellOn(deal)))} · ${escape(deal.fell_reason ?? "")}</span> ${sideLabel(deal.side)}</li>`).join("")}</ul>
220220 </section>`;
221221 const restoreCard =
222222 !mayRestore(who).ok
src/pages/progress.ts +1 −1
@@ -7,7 +7,7 @@ import { progress } from "../progress.ts";
77
88 /** "4 of 7 dates done · 1 overdue · closes …", or "All done · closed …" once the deal has closed. */
99 export function progressText(deal: DealView, on: string): string {
10 if (deal.closed) return `All done · closed ${spoken(closedOn(deal))}`;
10 if (deal.closed) return `All done · closed ${spoken(closedOn(deal), on)}`;
1111 const p = progress(deal, on);
1212 const overdue = p.overdue > 0 ? ` · ${p.overdue} overdue` : "";
1313 return `${p.done} of ${p.total} dates done${overdue} · closes ${spoken(deal.closing)}, ${relative(deal.closing, on)}`;
src/progress.test.ts +10 −1
@@ -3,7 +3,7 @@ import { expect, test } from "bun:test";
33 import { mkdtempSync } from "node:fs";
44 import { tmpdir } from "node:os";
55 import { join } from "node:path";
6 import { addDeadline, createDeal, getDeal, markDone, removeDeadline, type DealView } from "./deals.ts";
6 import { addDeadline, closedOn, createDeal, getDeal, markDone, removeDeadline, type DealView } from "./deals.ts";
77 import { openDb } from "./db.ts";
88 import { clock } from "./pages/clock.ts";
99 import { dealPage } from "./pages/deal.ts";
@@ -78,3 +78,12 @@ test("overdue shows only when there is some; a closed deal reads All done", () =
7878 expect(progress(closed, on)).toMatchObject({ done: closed.deadlines.length, overdue: 0 });
7979 });
8080
81 test("the All done line names the year of a closing from another year", () => {
82 const id = open();
83 for (const d of read(id).deadlines) markDone(db, alice, { id: d.id, done: true });
84 const closed = read(id);
85 const year = closedOn(closed).slice(0, 4);
86 const next = `${Number(year) + 1}${closedOn(closed).slice(4)}`;
87 expect(progressText(closed, next)).toContain(`, ${year}`);
88 expect(progressText(closed, closedOn(closed))).not.toContain(`, ${year}`);
89 });
src/sample.test.ts +26 −2
@@ -2,6 +2,7 @@ import { expect, test } from "bun:test";
22 import { mkdtempSync } from "node:fs";
33 import { tmpdir } from "node:os";
44 import { join } from "node:path";
5 import { zoneOf } from "./profile.ts";
56 import { openDb } from "./db.ts";
67 import { tally, bookLine } from "./book.ts";
78 import { book } from "./ics.ts";
@@ -9,10 +10,11 @@ import { dollars } from "./money.ts";
910 import { clock } from "./pages/clock.ts";
1011 import { people } from "./people.ts";
1112 import { thisWeek } from "./week.ts";
12 import { addDays, today, DEFAULT_ZONE } from "./dates.ts";
13 import { addDays, today, spoken, DEFAULT_ZONE } from "./dates.ts";
1314 import { createDeal, listDeals, markDone } from "./deals.ts";
1415 import { drafts, todaysDrafts, unsent } from "./reminders.ts";
15 import type { Who } from "./who.ts";
16 import { serve } from "./server.ts";
17 import { sign, type Who } from "./who.ts";
1618 import { isUntouched, refresh, restore, shiftSample, type SampleDates } from "./sample.ts";
1719
1820 const dates: SampleDates = {
@@ -232,6 +234,28 @@ test("every open sample inspection and walkthrough has a quarter-hour time and a
232234 check();
233235 });
234236
237 test("on a fresh boot the booted clock page gives the year of last year's closing, in literal words", async () => {
238 const KEY = "a-key-only-the-forge-holds";
239 const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-sample-year-")), identityKey: KEY });
240 try {
241 const identity = `u1|alice|user|${Date.now() + 600_000}`;
242 const res = await fetch(`http://${server.hostname}:${server.port}/`, {
243 headers: { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) },
244 });
245 const html = await res.text();
246 // The sample closed about a year ago (moved off a weekend, so the day is read from the page):
247 // the row must say the weekday, month, day and last year, and the weekday must be true.
outdated

This expectation is derived from spoken itself. Assert the literal text the page renders (weekday, month, day, last year) so it fails if spoken or the call site is wrong.

248 const row = html.match(/58 Larkspur Way<\/a> <span class="muted">closed (\w{3}), (\w{3}) (\d{1,2}), (\d{4}) ·/);
249 expect(row).not.toBeNull();
250 const [, weekday, month, day, year] = row!;
251 expect(Number(year)).toBe(Number(today(DEFAULT_ZONE).slice(0, 4)) - 1);
252 const real = new Date(`${month} ${day}, ${year} 12:00:00 UTC`).toLocaleDateString("en-US", { weekday: "short", timeZone: "UTC" });
253 expect(weekday).toBe(real);
254 } finally {
255 server.stop(true);
256 }
257 });
258
235259 test("on a fresh boot the first reminder for today is for a date already late or due today", () => {
236260 const db = openDb(mkdtempSync(join(tmpdir(), "app-sample-first-")));
237261 const alice: Who = { role: "user", id: "u1", name: "alice" };
src/terminal.test.ts +19
@@ -347,6 +347,25 @@ test("a closed deal's dates leave the date list and reminders, it is listed unde
347347 expect(lines(t).join("\n")).toContain("Inspection period ends — 88 Shut Ave");
348348 });
349349
350 test("the terminal's Closed list gives the year of a closing from another year", () => {
351 const other = createDeal(db, alice, {
352 openAnyway: true,
353 address: "91 Year Rd",
354 buyer: "B",
355 seller: "S",
356 contractDate: addDays(today(DEFAULT_ZONE), -7),
357 closingDate: addDays(today(DEFAULT_ZONE), 20),
358 });
359 if (!other.ok) throw new Error(other.message);
360 markDone(db, alice, { id: other.value.deadlines.find((d) => d.kind === "closing")!.id, done: true });
361 const closedDay = today(DEFAULT_ZONE);
362 const later = addDays(closedDay, 400);
363 const t = terminal(db, alice, { ...context, on: () => later });
364 t.press("d");
365 const words = new Date(`${closedDay}T12:00:00Z`).toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric", year: "numeric", timeZone: "UTC" });
366 expect(lines(t).join("\n")).toContain(`91 Year Rd — closed ${words}`);
367 });
368
350369 test("w lists the dates overdue or due within seven days, by day, with who owes each; x works there", () => {
351370 const soon = addDeadline(db, alice, { dealId: id, label: "Week check", due: addDays(today(DEFAULT_ZONE), 2), owes: "buyer" });
352371 if (!soon.ok) throw new Error(soon.message);
src/terminal.ts +1 −1
@@ -790,7 +790,7 @@ export function terminal(
790790 lines.push(
791791 "",
792792 bold(`Closed (${closed.length})`),
793 ...closed.map((d) => dim(` ${d.address} — closed ${spoken(closedOn(d))}`)),
793 ...closed.map((d) => dim(` ${d.address} — closed ${spoken(closedOn(d), day)}`)),

No test covers this call site. Add a terminal test with a closing in a different year from day that expects the year in the closed list.

794794 dim(showDone ? " Their dates are listed above; u on the Closing date reopens the deal." : " h shows their dates; u on the Closing date reopens the deal."),
795795 );
796796 const fell = all.filter((d) => d.fell_through);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs