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

Merged opened this

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

Merged

mason/deal-clock:mason/115-a-date-marked-done-says-the-day-it-was-d → main 1 commit fork

  • Merged. mason/115-a-date-marked-done-says-the-day-it-was-d was merged into main as 0bb7700.

Review

Sign in to review this change.
8 files changed +86 −5
contract/openapi.json +14
@@ -826,6 +826,13 @@
826826 "null"
827827 ]
828828 },
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 },
829836 "waived_at": {
830837 "type": [
831838 "string",
@@ -2755,6 +2762,13 @@
27552762 "null"
27562763 ]
27572764 },
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 },
27582772 "waived_at": {
27592773 "type": [
27602774 "string",
src/dates.ts +8
@@ -168,3 +168,11 @@ export function urgency(due: string, on: string, done: boolean): Urgency {
168168 /** `urgency` of a stored date: a waived one is grey and its own word, whatever its day. */
169169 export const urgencyOf = (d: { due: string; done_at: string | null; waived_at: string | null }, on: string): Urgency =>
170170 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 {
160160 readonly lead_days: number;
161161 }
162162 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;
163165 /** The latest change of who owes this date; null when it was never changed. */
164166 readonly owes_changed: { readonly from: PartyRole; readonly by: string; readonly on: string } | null;
165167 readonly moves: readonly Move[];
@@ -275,6 +277,7 @@ function assemble(deal: Deal, rows: Children): DealView {
275277 parties: rows.parties,
276278 deadlines: rows.deadlines.map(({ owes_from, owes_by, owes_on, ...d }) => ({
277279 ...d,
280 done_on: d.done_at === null ? null : today(new Date(d.done_at)),
278281 owes_changed: owes_from === null || owes_by === null || owes_on === null ? null : { from: owes_from, by: owes_by, on: owes_on },
279282 moves: moves.filter((m) => m.deadline_id === d.id),
280283 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 @@
66 */
77
88 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";
1010 import { isOpen, isWaivable, LEAD_MAX, LEAD_MIN, PARTY_LABEL, PARTY_ROLES } from "../deadlines.ts";
1111 import { escape } from "../http.ts";
1212 import { confirmRemove } from "./confirm.ts";
@@ -40,7 +40,7 @@ export const URGENCY_LABEL: Readonly<Record<Urgency, string>> = {
4040 /** "Due Thu, Oct 15 · in 3 days", or "Done". */
4141 export function dueLine(d: DeadlineView, on: string): string {
4242 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);
4444 return `Due ${spoken(d.due)} · ${relative(d.due, on)}`;
4545 }
4646
src/pages/timeline.ts +1 −1
@@ -26,7 +26,7 @@ export function timelinePage(input: { who: Who; agent?: Agent | undefined; deal:
2626 <p class="timeline-date">${escape(r.spoken)}</p>
2727 <p class="timeline-label"><b>${escape(r.label)}</b></p>
2828 <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>
3030 </li>`,
3131 )
3232 .join("");
src/routes.ts +1
@@ -256,6 +256,7 @@ export const DEAL: Schema = {
256256 owes: ROLE,
257257 what: { type: "string" },
258258 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." },
259260 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." },
260261 waived_by: { type: ["string", "null"], description: "Who recorded the waiver." },
261262 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 @@
55 * internal — no notes, drafts, reasons or contacts.
66 */
77
8 import { spoken, urgencyOf, type Urgency } from "./dates.ts";
8 import { doneLine, spoken, urgencyOf, type Urgency } from "./dates.ts";
99 import type { DealView } from "./deals.ts";
1010 import { owner } from "./week.ts";
1111
@@ -30,6 +30,8 @@ export interface TimelineRow {
3030 readonly role: string;
3131 readonly name: string | undefined;
3232 readonly status: TimelineStatus;
33 /** "Done Oct 30 · 3 days early" for a done date, else empty. */
34 readonly doneLine: string;
3335 readonly mark: string;
3436 readonly urgency: Urgency;
3537 }
@@ -38,6 +40,6 @@ export function timelineRows(deal: DealView, on: string): TimelineRow[] {
3840 return deal.deadlines.map((d) => {
3941 const u = urgencyOf(d, on);
4042 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 };
4244 });
4345 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs