Public: anyone can read this; the crew can change it.
A date marked done says the day it was done and whether that was early, on time or late #132
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/115-a-date-marked-done-says-the-day-it-was-d → main 1 commit fork
8 files
changed +86
−5
contract/openapi.json +14
| @@ -826,6 +826,13 @@ | ||
| 826 | 826 | "null" |
| 827 | 827 | ] |
| 828 | 828 | }, |
| 829 | "done_on": { | |
| 830 | "type": [ | |
| 831 | "string", | |
| 832 | "null" | |
| 833 | ], | |
| 834 | "description": "The day it was marked done, YYYY-MM-DD in the app's local calendar; null while open. Reopening clears it." | |
| 835 | }, | |
| 829 | 836 | "waived_at": { |
| 830 | 837 | "type": [ |
| 831 | 838 | "string", |
| @@ -2755,6 +2762,13 @@ | ||
| 2755 | 2762 | "null" |
| 2756 | 2763 | ] |
| 2757 | 2764 | }, |
| 2765 | "done_on": { | |
| 2766 | "type": [ | |
| 2767 | "string", | |
| 2768 | "null" | |
| 2769 | ], | |
| 2770 | "description": "The day it was marked done, YYYY-MM-DD in the app's local calendar; null while open. Reopening clears it." | |
| 2771 | }, | |
| 2758 | 2772 | "waived_at": { |
| 2759 | 2773 | "type": [ |
| 2760 | 2774 | "string", |
src/dates.ts +8
| @@ -168,3 +168,11 @@ export function urgency(due: string, on: string, done: boolean): Urgency { | ||
| 168 | 168 | /** `urgency` of a stored date: a waived one is grey and its own word, whatever its day. */ |
| 169 | 169 | export const urgencyOf = (d: { due: string; done_at: string | null; waived_at: string | null }, on: string): Urgency => |
| 170 | 170 | d.waived_at !== null ? "waived" : urgency(d.due, on, d.done_at !== null); |
| 171 | ||
| 172 | /** "Done Oct 30 · 3 days early", "Done Nov 2 · on time" or "Done Nov 4 · 2 days late": when a date was done against its due day. */ | |
| 173 | export function doneLine(due: string, doneOn: string): string { | |
| 174 | const late = daysBetween(due, doneOn); | |
| 175 | const days = (n: number): string => `${n} day${n === 1 ? "" : "s"}`; | |
| 176 | const how = late === 0 ? "on time" : late < 0 ? `${days(-late)} early` : `${days(late)} late`; | |
| 177 | return `Done ${short(doneOn)} · ${how}`; | |
| 178 | } |
src/deals.ts +3
| @@ -160,6 +160,8 @@ export interface Deadline { | ||
| 160 | 160 | readonly lead_days: number; |
| 161 | 161 | } |
| 162 | 162 | export interface DeadlineView extends Omit<Deadline, "owes_from" | "owes_by" | "owes_on"> { |
| 163 | /** The day it was marked done, by the app's own calendar (`today()`); null while open or after a reopen. */ | |
| 164 | readonly done_on: string | null; | |
| 163 | 165 | /** The latest change of who owes this date; null when it was never changed. */ |
| 164 | 166 | readonly owes_changed: { readonly from: PartyRole; readonly by: string; readonly on: string } | null; |
| 165 | 167 | readonly moves: readonly Move[]; |
| @@ -275,6 +277,7 @@ function assemble(deal: Deal, rows: Children): DealView { | ||
| 275 | 277 | parties: rows.parties, |
| 276 | 278 | deadlines: rows.deadlines.map(({ owes_from, owes_by, owes_on, ...d }) => ({ |
| 277 | 279 | ...d, |
| 280 | done_on: d.done_at === null ? null : today(new Date(d.done_at)), | |
| 278 | 281 | owes_changed: owes_from === null || owes_by === null || owes_on === null ? null : { from: owes_from, by: owes_by, on: owes_on }, |
| 279 | 282 | moves: moves.filter((m) => m.deadline_id === d.id), |
| 280 | 283 | nonBusinessDay: isOpen(d) && !isBusinessDay(d.due) ? { next: nextBusinessDay(d.due) } : null, |
src/doneon.test.ts added +53
| @@ -0,0 +1,53 @@ | ||
| 1 | /** A done date says the day it was done and whether that was early, on time or late. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { doneLine } from "./dates.ts"; | |
| 7 | import { addDeadline, createDeal, getDeal, markDone } from "./deals.ts"; | |
| 8 | import { openDb } from "./db.ts"; | |
| 9 | import { dealSheets } from "./pages/sheet.ts"; | |
| 10 | import { timelinePage } from "./pages/timeline.ts"; | |
| 11 | import type { Who } from "./who.ts"; | |
| 12 | ||
| 13 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 14 | const db = openDb(mkdtempSync(join(tmpdir(), "app-doneon-"))); | |
| 15 | const made = createDeal(db, alice, { openAnyway: true, address: "5 Done Way", buyer: "Ann", seller: "Sam", contractDate: "2026-10-01", closingDate: "2026-12-20" }); | |
| 16 | if (!made.ok) throw new Error(made.message); | |
| 17 | const id = made.value.id; | |
| 18 | const add = (label: string) => { | |
| 19 | const r = addDeadline(db, alice, { dealId: id, label, due: "2026-11-02", owes: "buyer", what: "" }); | |
| 20 | if (!r.ok) throw new Error(r.message); | |
| 21 | return r.value.id; | |
| 22 | }; | |
| 23 | const doneAt = (did: number, day: string) => { | |
| 24 | markDone(db, alice, { id: did, done: true }); | |
| 25 | db.query("UPDATE deadline SET done_at = ?1 WHERE id = ?2").run(`${day}T12:00:00.000Z`, did); | |
| 26 | }; | |
| 27 | const read = (did: number) => getDeal(db, alice, { id }).value!.deadlines.find((d) => d.id === did)!; | |
| 28 | ||
| 29 | test("doneLine reads early, on time and late", () => { | |
| 30 | expect(doneLine("2026-11-02", "2026-10-30")).toBe("Done Oct 30 · 3 days early"); | |
| 31 | expect(doneLine("2026-11-02", "2026-11-02")).toBe("Done Nov 2 · on time"); | |
| 32 | expect(doneLine("2026-11-02", "2026-11-04")).toBe("Done Nov 4 · 2 days late"); | |
| 33 | expect(doneLine("2026-11-02", "2026-11-03")).toBe("Done Nov 3 · 1 day late"); | |
| 34 | }); | |
| 35 | ||
| 36 | test("the deal page and timeline show the wording; reopening clears it", () => { | |
| 37 | const early = add("Early one"); | |
| 38 | const late = add("Late one"); | |
| 39 | doneAt(early, "2026-10-30"); | |
| 40 | doneAt(late, "2026-11-04"); | |
| 41 | expect(read(early).done_on).toBe("2026-10-30"); | |
| 42 | const deal = getDeal(db, alice, { id }).value!; | |
| 43 | expect(dealSheets(deal, alice, "2026-11-08", "/")).toContain("Done Oct 30 · 3 days early"); | |
| 44 | const tl = timelinePage({ who: alice, deal, on: "2026-11-08" }); | |
| 45 | expect(tl).toContain("Done Oct 30 · 3 days early"); | |
| 46 | expect(tl).toContain("Done Nov 4 · 2 days late"); | |
| 47 | ||
| 48 | markDone(db, alice, { id: early, done: false }); | |
| 49 | expect(read(early).done_on).toBeNull(); | |
| 50 | expect(read(early).done_at).toBeNull(); | |
| 51 | markDone(db, alice, { id: early, done: true }); | |
| 52 | expect(read(early).done_on).toMatch(/^\d{4}-\d{2}-\d{2}$/); | |
| 53 | }); |
src/pages/sheet.ts +2 −2
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import { BODY_MAX, canChange, NOTE_MAX, ROLL_REASON, REASON_MAX, SUBJECT_MAX, type DealView, type DeadlineView } from "../deals.ts"; |
| 9 | import { relative, short, spoken, urgencyOf, type Urgency } from "../dates.ts"; | |
| 9 | import { doneLine, relative, short, spoken, urgencyOf, type Urgency } from "../dates.ts"; | |
| 10 | 10 | import { isOpen, isWaivable, LEAD_MAX, LEAD_MIN, PARTY_LABEL, PARTY_ROLES } from "../deadlines.ts"; |
| 11 | 11 | import { escape } from "../http.ts"; |
| 12 | 12 | import { confirmRemove } from "./confirm.ts"; |
| @@ -40,7 +40,7 @@ export const URGENCY_LABEL: Readonly<Record<Urgency, string>> = { | ||
| 40 | 40 | /** "Due Thu, Oct 15 · in 3 days", or "Done". */ |
| 41 | 41 | export function dueLine(d: DeadlineView, on: string): string { |
| 42 | 42 | if (d.waived_at !== null) return `Waived ${spoken(d.waived_at.slice(0, 10))}${d.waived_by === null ? "" : ` by ${d.waived_by}`} · was due ${spoken(d.due)}`; |
| 43 | if (d.done_at !== null) return `Done · was due ${spoken(d.due)}`; | |
| 43 | if (d.done_at !== null) return d.done_on === null ? "Done" : doneLine(d.due, d.done_on); | |
| 44 | 44 | return `Due ${spoken(d.due)} · ${relative(d.due, on)}`; |
| 45 | 45 | } |
| 46 | 46 |
src/pages/timeline.ts +1 −1
| @@ -26,7 +26,7 @@ export function timelinePage(input: { who: Who; agent?: Agent | undefined; deal: | ||
| 26 | 26 | <p class="timeline-date">${escape(r.spoken)}</p> |
| 27 | 27 | <p class="timeline-label"><b>${escape(r.label)}</b></p> |
| 28 | 28 | <p class="timeline-owner">${escape(r.role)}${r.name === undefined ? "" : ` · ${escape(r.name)}`}</p> |
| 29 | <p class="timeline-status"><span aria-hidden="true">${r.mark}</span> ${r.status}</p> | |
| 29 | <p class="timeline-status"><span aria-hidden="true">${r.mark}</span> ${r.doneLine === "" ? r.status : escape(r.doneLine)}</p> | |
| 30 | 30 | </li>`, |
| 31 | 31 | ) |
| 32 | 32 | .join(""); |
src/routes.ts +1
| @@ -256,6 +256,7 @@ export const DEAL: Schema = { | ||
| 256 | 256 | owes: ROLE, |
| 257 | 257 | what: { type: "string" }, |
| 258 | 258 | done_at: { type: ["string", "null"] }, |
| 259 | done_on: { type: ["string", "null"], description: "The day it was marked done, YYYY-MM-DD in the app's local calendar; null while open. Reopening clears it." }, | |
| 259 | 260 | waived_at: { type: ["string", "null"], description: "When the buyer waived this date on purpose; null while it stands. A waived date is settled: no reminders, flags or conflicts." }, |
| 260 | 261 | waived_by: { type: ["string", "null"], description: "Who recorded the waiver." }, |
| 261 | 262 | note: { type: "string", maxLength: 200, description: "The agent's working note on this date; empty when none. Internal, never sent to a client." }, |
src/timeline.ts +4 −2
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * internal — no notes, drafts, reasons or contacts. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { spoken, urgencyOf, type Urgency } from "./dates.ts"; | |
| 8 | import { doneLine, spoken, urgencyOf, type Urgency } from "./dates.ts"; | |
| 9 | 9 | import type { DealView } from "./deals.ts"; |
| 10 | 10 | import { owner } from "./week.ts"; |
| 11 | 11 | |
| @@ -30,6 +30,8 @@ export interface TimelineRow { | ||
| 30 | 30 | readonly role: string; |
| 31 | 31 | readonly name: string | undefined; |
| 32 | 32 | readonly status: TimelineStatus; |
| 33 | /** "Done Oct 30 · 3 days early" for a done date, else empty. */ | |
| 34 | readonly doneLine: string; | |
| 33 | 35 | readonly mark: string; |
| 34 | 36 | readonly urgency: Urgency; |
| 35 | 37 | } |
| @@ -38,6 +40,6 @@ export function timelineRows(deal: DealView, on: string): TimelineRow[] { | ||
| 38 | 40 | return deal.deadlines.map((d) => { |
| 39 | 41 | const u = urgencyOf(d, on); |
| 40 | 42 | const { name, role } = owner(deal, d); |
| 41 | return { label: d.label, due: d.due, spoken: spoken(d.due), role, name, status: STATUS[u].word, mark: STATUS[u].mark, urgency: u }; | |
| 43 | return { label: d.label, due: d.due, spoken: spoken(d.due), role, name, status: STATUS[u].word, doneLine: u === "done" && d.done_on !== null ? doneLine(d.due, d.done_on) : "", mark: STATUS[u].mark, urgency: u }; | |
| 42 | 44 | }); |
| 43 | 45 | } |
new above
offline