Public: anyone can read this; the crew can change it.
A date from another year says its year, so the Closed list never shows last November's sale as "closed Sun, Nov 9" the day before Nov 9 #198
mason/deal-clock:mason/197-a-date-from-another-year-says-its-year-s → main 4 commits fork
7 files
changed +40
−6
src/dates.test.ts +13
| @@ -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,14 @@ 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("same year omits the year, another year says it", () => { | |
| 150 | expect(spoken("2026-11-09", "2026-11-08")).toBe("Mon, Nov 9"); | |
| 151 | expect(spoken("2025-11-09", "2026-11-08")).toBe("Sun, Nov 9, 2025"); | |
| 152 | expect(spoken("2025-11-09")).toBe("Sun, Nov 9"); | |
| 153 | }); | |
| 154 | test("Dec 31 to Jan 1 follows the agent's zone", () => { | |
| 155 | const now = new Date("2027-01-01T03:00:00Z"); // Dec 31 in New York, Jan 1 in UTC | |
| 156 | expect(spoken("2026-12-31", today("America/New_York", now))).toBe("Thu, Dec 31"); | |
| 157 | expect(spoken("2026-12-31", today("UTC", now))).toBe("Thu, Dec 31, 2026"); | |
| 158 | }); |
src/dates.ts +15 −2
| @@ -186,8 +186,21 @@ 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 | const SPOKEN_YEAR = new Intl.DateTimeFormat("en-US", { | |
| 190 | weekday: "short", | |
| 191 | month: "short", | |
| 192 | day: "numeric", | |
| 193 | year: "numeric", | |
| 194 | timeZone: "UTC", | |
| 195 | }); | |
| 196 | ||
| 197 | /** | |
| 198 | * "Fri, Oct 16" — how a person reads a date in a sentence. Given the agent's | |
| 199 | * `on` (today, in their zone), a date from another calendar year also says its | |
| 200 | * year: "Sun, Nov 9, 2025". Without `on` the year is never spoken. | |
| 201 | */ | |
| 202 | export const spoken = (date: string, on?: string): string => | |
| 203 | on !== undefined && date.slice(0, 4) !== on.slice(0, 4) ? SPOKEN_YEAR.format(toMs(date)) : SPOKEN.format(toMs(date)); | |
| 191 | 204 | |
| 192 | 205 | const WEEKDAY = new Intl.DateTimeFormat("en-US", { weekday: "long", timeZone: "UTC" }); |
| 193 | 206 |
src/pages/clock.ts +1 −1
| @@ -215,7 +215,7 @@ function render(input: { | ||
| 215 | 215 | : `<section id="closed" class="card" data-live="deal.changed"> |
| 216 | 216 | <h2>Closed <span class="muted">· ${closed.length + fell.length}</span></h2> |
| 217 | 217 | ${who.role === "anon" ? "" : `<p class="small"><a href="/deals/csv?closed=1" download>Download spreadsheet with closed deals</a></p>`} |
| 218 | <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> | |
| 218 | <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> | |
| 219 | 219 | </section>`; |
| 220 | 220 | const restoreCard = |
| 221 | 221 | !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 +7
| @@ -78,3 +78,10 @@ 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 | ||
| 82 | test("a closed deal from another year says its year in the progress line", () => { | |
| 83 | const id = open(); | |
| 84 | const deal = { ...read(id), closed: true, closing: "2025-11-09" } as DealView; | |
| 85 | expect(progressText(deal, "2026-11-08")).toBe("All done · closed Sun, Nov 9, 2025"); | |
| 86 | expect(progressText(deal, "2025-11-08")).toBe("All done · closed Sun, Nov 9"); | |
| 87 | }); |
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)}`)), | |
| 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); |
src/week.page.test.ts +2 −1
| @@ -36,7 +36,8 @@ test("lists overdue and coming dates with deal, owner and state, and no controls | ||
| 36 | 36 | const card = clock.slice(clock.indexOf('id="week"')); |
| 37 | 37 | expect(card).toContain('href="/week"'); |
| 38 | 38 | const labels = (h: string) => [...h.matchAll(/<b>([^<]+)<\/b>/g)].map((m) => m[1]); |
| 39 | for (const l of labels(html.slice(html.indexOf("timeline-list"))).filter((l) => !days.includes(l))) expect(clock).toContain(l!); | |
| 39 | // The sheet adds an inspection's or walkthrough's time and place to the label; the clock card does not, so compare the label itself. | |
| 40 | for (const l of labels(html.slice(html.indexOf("timeline-list"))).filter((l) => !days.includes(l))) expect(clock).toContain(l!.split(" · ")[0]!); | |
| 40 | 41 | }); |
| 41 | 42 | |
| 42 | 43 | test("omits done dates and closed deals: one row per open date in the window", async () => { |
new above
offline