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
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/206-a-date-from-another-year-says-its-year-o → main 3 commits fork 2 threads · 2 unresolved
8 files
changed +76
−8
src/dates.test.ts +12
| @@ -12,6 +12,8 @@ import { | ||
| 12 | 12 | isHoliday, |
| 13 | 13 | nextBusinessDay, |
| 14 | 14 | relative, |
| 15 | spoken, | |
| 16 | today, | |
| 15 | 17 | urgency, |
| 16 | 18 | } from "./dates.ts"; |
| 17 | 19 | import { DEFAULT_LENGTHS, schedule } from "./deadlines.ts"; |
| @@ -143,3 +145,13 @@ test("business days step over a holiday; calendar days do not", () => { | ||
| 143 | 145 | expect(addBusinessDays("2026-11-27", -1)).toBe("2026-11-25"); |
| 144 | 146 | expect(addDays("2026-11-25", 1)).toBe("2026-11-26"); |
| 145 | 147 | }); |
| 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", { | ||
| 186 | 186 | timeZone: "UTC", |
| 187 | 187 | }); |
| 188 | 188 | |
| 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)); | |
| 191 | 195 | |
| 192 | 196 | const WEEKDAY = new Intl.DateTimeFormat("en-US", { weekday: "long", timeZone: "UTC" }); |
| 193 | 197 |
src/pages/clock.ts +1 −1
| @@ -216,7 +216,7 @@ function render(input: { | ||
| 216 | 216 | : `<section id="closed" class="card" data-live="deal.changed"> |
| 217 | 217 | <h2>Closed <span class="muted">· ${closed.length + fell.length}</span></h2> |
| 218 | 218 | ${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> | |
| 220 | 220 | </section>`; |
| 221 | 221 | const restoreCard = |
| 222 | 222 | !mayRestore(who).ok |
src/pages/progress.ts +1 −1
| @@ -7,7 +7,7 @@ import { progress } from "../progress.ts"; | ||
| 7 | 7 | |
| 8 | 8 | /** "4 of 7 dates done · 1 overdue · closes …", or "All done · closed …" once the deal has closed. */ |
| 9 | 9 | 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)}`; | |
| 11 | 11 | const p = progress(deal, on); |
| 12 | 12 | const overdue = p.overdue > 0 ? ` · ${p.overdue} overdue` : ""; |
| 13 | 13 | 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"; | ||
| 3 | 3 | import { mkdtempSync } from "node:fs"; |
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | 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"; | |
| 7 | 7 | import { openDb } from "./db.ts"; |
| 8 | 8 | import { clock } from "./pages/clock.ts"; |
| 9 | 9 | import { dealPage } from "./pages/deal.ts"; |
| @@ -78,3 +78,12 @@ test("overdue shows only when there is some; a closed deal reads All done", () = | ||
| 78 | 78 | expect(progress(closed, on)).toMatchObject({ done: closed.deadlines.length, overdue: 0 }); |
| 79 | 79 | }); |
| 80 | 80 | |
| 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"; | ||
| 2 | 2 | import { mkdtempSync } from "node:fs"; |
| 3 | 3 | import { tmpdir } from "node:os"; |
| 4 | 4 | import { join } from "node:path"; |
| 5 | import { zoneOf } from "./profile.ts"; | |
| 5 | 6 | import { openDb } from "./db.ts"; |
| 6 | 7 | import { tally, bookLine } from "./book.ts"; |
| 7 | 8 | import { book } from "./ics.ts"; |
| @@ -9,10 +10,11 @@ import { dollars } from "./money.ts"; | ||
| 9 | 10 | import { clock } from "./pages/clock.ts"; |
| 10 | 11 | import { people } from "./people.ts"; |
| 11 | 12 | import { thisWeek } from "./week.ts"; |
| 12 | import { addDays, today, DEFAULT_ZONE } from "./dates.ts"; | |
| 13 | import { addDays, today, spoken, DEFAULT_ZONE } from "./dates.ts"; | |
| 13 | 14 | import { createDeal, listDeals, markDone } from "./deals.ts"; |
| 14 | 15 | 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"; | |
| 16 | 18 | import { isUntouched, refresh, restore, shiftSample, type SampleDates } from "./sample.ts"; |
| 17 | 19 | |
| 18 | 20 | const dates: SampleDates = { |
| @@ -232,6 +234,28 @@ test("every open sample inspection and walkthrough has a quarter-hour time and a | ||
| 232 | 234 | check(); |
| 233 | 235 | }); |
| 234 | 236 | |
| 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. | |
| 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 | ||
| 235 | 259 | test("on a fresh boot the first reminder for today is for a date already late or due today", () => { |
| 236 | 260 | const db = openDb(mkdtempSync(join(tmpdir(), "app-sample-first-"))); |
| 237 | 261 | 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 | ||
| 347 | 347 | expect(lines(t).join("\n")).toContain("Inspection period ends — 88 Shut Ave"); |
| 348 | 348 | }); |
| 349 | 349 | |
| 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 | ||
| 350 | 369 | test("w lists the dates overdue or due within seven days, by day, with who owes each; x works there", () => { |
| 351 | 370 | const soon = addDeadline(db, alice, { dealId: id, label: "Week check", due: addDays(today(DEFAULT_ZONE), 2), owes: "buyer" }); |
| 352 | 371 | if (!soon.ok) throw new Error(soon.message); |
src/terminal.ts +1 −1
| @@ -790,7 +790,7 @@ export function terminal( | ||
| 790 | 790 | lines.push( |
| 791 | 791 | "", |
| 792 | 792 | 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 |
||
| 794 | 794 | 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."), |
| 795 | 795 | ); |
| 796 | 796 | const fell = all.filter((d) => d.fell_through); |
new above
offline
This expectation is derived from
spokenitself. Assert the literal text the page renders (weekday, month, day, last year) so it fails ifspokenor the call site is wrong.