Public: anyone can read this; the crew can change it.
A date that lands on a weekend or a US federal holiday is flagged with the next business day, and moving it there is one tap #95
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/84-a-date-that-lands-on-a-weekend-or-a-us-f → main 2 commits fork 1 thread · 1 unresolved
14 files
changed +276
−13
README.md +1
| @@ -118,6 +118,7 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 118 | 118 | the clock. A date you added has a Remove this date button in its sheet |
| 119 | 119 | (it asks once, like every removal, including Remove this deal), for when the contract drops it; the standard dates cannot be removed, only |
| 120 | 120 | moved or marked done. |
| 121 | A date on a weekend or US federal holiday says "not a business day · next is Mon, Nov 30"; tap Move to (N in the terminal) to take that day, reason kept. | |
| 121 | 122 | 10. **Open a new deal.** Back on the clock, tap New deal. Type an address, |
| 122 | 123 | buyer, seller, contract date and closing date. The standard lengths are |
| 123 | 124 | already filled in (inspection 10 days, appraisal 21, financing 30, title 14, |
contract/openapi.json +26
| @@ -672,6 +672,19 @@ | ||
| 672 | 672 | "items": { |
| 673 | 673 | "type": "object" |
| 674 | 674 | } |
| 675 | }, | |
| 676 | "nonBusinessDay": { | |
| 677 | "type": [ | |
| 678 | "object", | |
| 679 | "null" | |
| 680 | ], | |
| 681 | "description": "An open date due on a weekend or US federal holiday: next is the business day it rolls to. Null otherwise.", | |
| 682 | "properties": { | |
| 683 | "next": { | |
| 684 | "type": "string", | |
| 685 | "format": "date" | |
| 686 | } | |
| 687 | } | |
| 675 | 688 | } |
| 676 | 689 | } |
| 677 | 690 | } |
| @@ -1975,6 +1988,19 @@ | ||
| 1975 | 1988 | "items": { |
| 1976 | 1989 | "type": "object" |
| 1977 | 1990 | } |
| 1991 | }, | |
| 1992 | "nonBusinessDay": { | |
| 1993 | "type": [ | |
| 1994 | "object", | |
| 1995 | "null" | |
| 1996 | ], | |
| 1997 | "description": "An open date due on a weekend or US federal holiday: next is the business day it rolls to. Null otherwise.", | |
| 1998 | "properties": { | |
| 1999 | "next": { | |
| 2000 | "type": "string", | |
| 2001 | "format": "date" | |
| 2002 | } | |
| 2003 | } | |
| 1978 | 2004 | } |
| 1979 | 2005 | } |
| 1980 | 2006 | } |
docs/TECHNICAL.md +4
| @@ -41,6 +41,10 @@ date, to the parties a `day_of` reminder goes to, dated the day of the move; its | ||
| 41 | 41 | words name the old and new dates, never the move's reason. Sent and declined |
| 42 | 42 | rows are keyed by `due` (a plain date) and `move_id` (the latest move for `moved`, else 0; see `moveKey`), so |
| 43 | 43 | an earlier notice stays sent and a date moved back and forth is told afresh. |
| 44 | An open date due on a weekend or US federal holiday (`src/dates.ts`, computed, no | |
| 45 | table) carries `deadlines[].nonBusinessDay: { next }` in the API and in MCP | |
| 46 | `get_deal` (`null` otherwise); the sheet's and deal page's *Move to* button posts | |
| 47 | `POST /deadlines/:id/move` with the reason "Rolled to the next business day". | |
| 44 | 48 | `deadline_move.notify` is 1 only for moves made after the moment existed. |
| 45 | 49 | `send_reminder` and the decline and undo doors take `moment: "moved"`. |
| 46 | 50 |
src/dates.test.ts +39
| @@ -7,7 +7,10 @@ import { | ||
| 7 | 7 | addBusinessDays, |
| 8 | 8 | addDays, |
| 9 | 9 | daysBetween, |
| 10 | isBusinessDay, | |
| 10 | 11 | isDate, |
| 12 | isHoliday, | |
| 13 | nextBusinessDay, | |
| 11 | 14 | relative, |
| 12 | 15 | urgency, |
| 13 | 16 | } from "./dates.ts"; |
| @@ -102,3 +105,39 @@ test("urgency: done is grey, past due red, within three days amber", () => { | ||
| 102 | 105 | expect(relative("2026-10-15", on)).toBe("in 3 days"); |
| 103 | 106 | expect(relative("2026-10-10", on)).toBe("2 days ago"); |
| 104 | 107 | }); |
| 108 | ||
| 109 | test("US federal holidays are computed for any year, as observed", () => { | |
| 110 | const all = (year: number) => { | |
| 111 | const found: string[] = []; | |
| 112 | for (let at = `${year}-01-01`; at < `${year + 1}-01-01`; at = addDays(at, 1)) if (isHoliday(at)) found.push(at); | |
| 113 | return found; | |
| 114 | }; | |
| 115 | // 2026: July 4 is a Saturday, so Friday the 3rd is observed. | |
| 116 | expect(all(2026)).toEqual([ | |
| 117 | "2026-01-01", "2026-01-19", "2026-02-16", "2026-05-25", "2026-06-19", "2026-07-03", | |
| 118 | "2026-09-07", "2026-10-12", "2026-11-11", "2026-11-26", "2026-12-25", | |
| 119 | ]); | |
| 120 | // 2027: July 4 is a Sunday (Monday the 5th), Christmas a Saturday (Friday the 24th), | |
| 121 | // and New Year 2028 falls on a Saturday, observed Friday, Dec 31 2027. | |
| 122 | expect(all(2027)).toEqual([ | |
| 123 | "2027-01-01", "2027-01-18", "2027-02-15", "2027-05-31", "2027-06-18", "2027-07-05", | |
| 124 | "2027-09-06", "2027-10-11", "2027-11-11", "2027-11-25", "2027-12-24", "2027-12-31", | |
| 125 | ]); | |
| 126 | }); | |
| 127 | ||
| 128 | test("a business day is neither weekend nor holiday, and the next one is found", () => { | |
| 129 | expect(isBusinessDay("2026-11-27")).toBe(true); | |
| 130 | expect(isBusinessDay("2026-11-26")).toBe(false); | |
| 131 | expect(isBusinessDay("2026-11-28")).toBe(false); | |
| 132 | expect(nextBusinessDay("2026-11-28")).toBe("2026-11-30"); | |
| 133 | expect(nextBusinessDay("2026-11-30")).toBe("2026-11-30"); | |
| 134 | // Christmas Friday then a weekend: Monday. | |
| 135 | expect(nextBusinessDay("2026-12-25")).toBe("2026-12-28"); | |
| 136 | }); | |
| 137 | ||
| 138 | test("business days step over a holiday; calendar days do not", () => { | |
| 139 | // Wed Nov 25 + 1 business day skips Thanksgiving: Friday the 27th. | |
| 140 | expect(addBusinessDays("2026-11-25", 1)).toBe("2026-11-27"); | |
| 141 | expect(addBusinessDays("2026-11-27", -1)).toBe("2026-11-25"); | |
| 142 | expect(addDays("2026-11-25", 1)).toBe("2026-11-26"); | |
| 143 | }); |
src/dates.ts +61 −2
| @@ -44,13 +44,72 @@ export const isWeekend = (date: string): boolean => { | ||
| 44 | 44 | return day === 0 || day === 6; |
| 45 | 45 | }; |
| 46 | 46 | |
| 47 | /** `date` moved by `days` weekdays: weekends are stepped over, not counted. */ | |
| 47 | const pad = (n: number): string => String(n).padStart(2, "0"); | |
| 48 | ||
| 49 | /** The `n`th (1-based) given weekday (0 = Sunday) of a month (1-based); `n` of -1 is the last. */ | |
| 50 | function nthWeekday(year: number, month: number, weekday: number, n: number): string { | |
| 51 | if (n > 0) { | |
| 52 | const first = new Date(Date.UTC(year, month - 1, 1)).getUTCDay(); | |
| 53 | return `${year}-${pad(month)}-${pad(1 + ((weekday - first + 7) % 7) + (n - 1) * 7)}`; | |
| 54 | } | |
| 55 | const last = new Date(Date.UTC(year, month, 0)); | |
| 56 | return `${year}-${pad(month)}-${pad(last.getUTCDate() - ((last.getUTCDay() - weekday + 7) % 7))}`; | |
| 57 | } | |
| 58 | ||
| 59 | /** A fixed-date holiday as the government observes it: a Saturday on the Friday before, a Sunday on the Monday after. */ | |
| 60 | function observed(year: number, month: number, day: number): string { | |
| 61 | const date = `${year}-${pad(month)}-${pad(day)}`; | |
| 62 | const weekday = new Date(toMs(date)).getUTCDay(); | |
| 63 | return weekday === 6 ? addDays(date, -1) : weekday === 0 ? addDays(date, 1) : date; | |
| 64 | } | |
| 65 | ||
| 66 | const holidayYears = new Map<number, Set<string>>(); | |
| 67 | ||
| 68 | /** The days US federal offices are closed in `year`, as observed. */ | |
| 69 | function holidaysOf(year: number): Set<string> { | |
| 70 | let set = holidayYears.get(year); | |
| 71 | if (set === undefined) { | |
| 72 | set = new Set([ | |
| 73 | observed(year, 1, 1), // New Year's Day | |
| 74 | nthWeekday(year, 1, 1, 3), // Martin Luther King Jr. Day | |
| 75 | nthWeekday(year, 2, 1, 3), // Washington's Birthday | |
| 76 | nthWeekday(year, 5, 1, -1), // Memorial Day | |
| 77 | observed(year, 6, 19), // Juneteenth | |
| 78 | observed(year, 7, 4), // Independence Day | |
| 79 | nthWeekday(year, 9, 1, 1), // Labor Day | |
| 80 | nthWeekday(year, 10, 1, 2), // Columbus Day | |
| 81 | observed(year, 11, 11), // Veterans Day | |
| 82 | nthWeekday(year, 11, 4, 4), // Thanksgiving | |
| 83 | observed(year, 12, 25), // Christmas Day | |
| 84 | ]); | |
| 85 | // January 1 of next year observed on this December 31 (a Saturday new year). | |
| 86 | const next = observed(year + 1, 1, 1); | |
| 87 | if (next.startsWith(`${year}-`)) set.add(next); | |
| 88 | holidayYears.set(year, set); | |
| 89 | } | |
| 90 | return set; | |
| 91 | } | |
| 92 | ||
| 93 | /** Is `date` a US federal holiday, on the day it is observed? */ | |
| 94 | export const isHoliday = (date: string): boolean => holidaysOf(+date.slice(0, 4)).has(date); | |
| 95 | ||
| 96 | /** Not a weekend and not a US federal holiday. */ | |
| 97 | export const isBusinessDay = (date: string): boolean => !isWeekend(date) && !isHoliday(date); | |
| 98 | ||
| 99 | /** `date` itself when it is a business day, else the next one after it. */ | |
| 100 | export function nextBusinessDay(date: string): string { | |
| 101 | let at = date; | |
| 102 | while (!isBusinessDay(at)) at = addDays(at, 1); | |
| 103 | return at; | |
| 104 | } | |
| 105 | ||
| 106 | /** `date` moved by `days` business days: weekends and US federal holidays are stepped over, not counted. */ | |
| 48 | 107 | export function addBusinessDays(date: string, days: number): string { |
| 49 | 108 | const step = days < 0 ? -1 : 1; |
| 50 | 109 | let at = date; |
| 51 | 110 | for (let left = Math.abs(days); left > 0; ) { |
| 52 | 111 | at = addDays(at, step); |
| 53 | if (!isWeekend(at)) left--; | |
| 112 | if (isBusinessDay(at)) left--; | |
| 54 | 113 | } |
| 55 | 114 | return at; |
| 56 | 115 | } |
src/deals.test.ts +1 −1
| @@ -88,7 +88,7 @@ test("opening a deal computes its dates, with the buyer and seller as parties", | ||
| 88 | 88 | ["seller", "Sam Seller"], |
| 89 | 89 | ]); |
| 90 | 90 | const custom = open({ lengths: { inspection: "7" }, businessDays: "on" }); |
| 91 | expect(due(custom, "inspection").due).toBe("2026-10-12"); // 7 weekdays from a Thursday | |
| 91 | expect(due(custom, "inspection").due).toBe("2026-10-13"); // 7 business days from a Thursday, stepping over Columbus Day (Oct 12) | |
| 92 | 92 | expect(custom.business_days).toBe(1); |
| 93 | 93 | }); |
| 94 | 94 |
src/deals.ts +6 −1
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | |
| 9 | 9 | import type { Database } from "bun:sqlite"; |
| 10 | 10 | import { permit } from "./contract.ts"; |
| 11 | import { isDate, today } from "./dates.ts"; | |
| 11 | import { isBusinessDay, isDate, nextBusinessDay, today } from "./dates.ts"; | |
| 12 | 12 | import { |
| 13 | 13 | DEFAULT_LENGTHS, |
| 14 | 14 | isClosed, |
| @@ -113,6 +113,8 @@ export interface Deadline { | ||
| 113 | 113 | } |
| 114 | 114 | export interface DeadlineView extends Deadline { |
| 115 | 115 | readonly moves: readonly Move[]; |
| 116 | /** An open date due on a weekend or US federal holiday: the business day it rolls to. Null otherwise. */ | |
| 117 | readonly nonBusinessDay: { readonly next: string } | null; | |
| 116 | 118 | } |
| 117 | 119 | /** The day the Closing date was marked done, by the app's own calendar (the one `today()` keeps). */ |
| 118 | 120 | export const closedOn = (deal: { deadlines: readonly { kind: Kind; done_at: string | null }[]; closing: string }): string => { |
| @@ -161,6 +163,8 @@ export function message(value: unknown, min: number, max: number): string | unde | ||
| 161 | 163 | |
| 162 | 164 | export const SUBJECT_MAX = 150; |
| 163 | 165 | export const REASON_MAX = 200; |
| 166 | /** Why a move is recorded when the agent takes the next-business-day suggestion. */ | |
| 167 | export const ROLL_REASON = "Rolled to the next business day"; | |
| 164 | 168 | export const BODY_MAX = 2000; |
| 165 | 169 | |
| 166 | 170 | /** The name a row is written under: the person, as the forge signed them. */ |
| @@ -208,6 +212,7 @@ function assemble(deal: Deal, rows: Children): DealView { | ||
| 208 | 212 | deadlines: rows.deadlines.map((d) => ({ |
| 209 | 213 | ...d, |
| 210 | 214 | moves: moves.filter((m) => m.deadline_id === d.id), |
| 215 | nonBusinessDay: d.done_at === null && !isBusinessDay(d.due) ? { next: nextBusinessDay(d.due) } : null, | |
| 211 | 216 | })), |
| 212 | 217 | sent: rows.sent.map((m) => withHref(m, rows.parties)), |
| 213 | 218 | declined: rows.declined, |
src/nonbusiness.test.ts added +78
| @@ -0,0 +1,78 @@ | ||
| 1 | /** A date on a weekend or holiday is flagged with the next business day, and moving it is one tap. */ | |
| 2 | import { afterAll, beforeEach, 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 type { DealView } from "./deals.ts"; | |
| 7 | import { weekCard } from "./pages/clock.ts"; | |
| 8 | import { forgetRationing } from "./security.ts"; | |
| 9 | import { serve } from "./server.ts"; | |
| 10 | import { sign } from "./who.ts"; | |
| 11 | ||
| 12 | const KEY = "a-key-only-the-forge-holds"; | |
| 13 | const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-nbd-")), identityKey: KEY }); | |
| 14 | const base = `http://${server.hostname}:${server.port}`; | |
| 15 | afterAll(() => server.stop(true)); | |
| 16 | beforeEach(forgetRationing); | |
| 17 | const identity = `u9|nora|user|${Date.now() + 600_000}`; | |
| 18 | const me = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) }; | |
| 19 | const json = { ...me, "content-type": "application/json" }; | |
| 20 | const api = async (path: string): Promise<DealView> => (await (await fetch(base + path, { headers: me })).json()) as DealView; | |
| 21 | ||
| 22 | const moveTo = (id: number, due: string) => { | |
| 23 | const body = new FormData(); | |
| 24 | body.set("due", due); | |
| 25 | body.set("reason", "Seller asked"); | |
| 26 | return fetch(`${base}/deadlines/${id}/move`, { method: "POST", body, headers: me, redirect: "manual" }); | |
| 27 | }; | |
| 28 | ||
| 29 | async function dealWithSaturday(): Promise<{ deal: DealView; id: number }> { | |
| 30 | const made = await fetch(base + "/api/deals", { | |
| 31 | method: "POST", | |
| 32 | headers: json, | |
| 33 | body: JSON.stringify({ address: "5 Weekend Way", open_anyway: true, buyer: "A", seller: "B", contract_date: "2026-10-01", closing_date: "2026-12-01" }), | |
| 34 | }); | |
| 35 | const deal = (await made.json()) as DealView; | |
| 36 | const inspection = deal.deadlines.find((d) => d.kind === "inspection")!; | |
| 37 | expect((await moveTo(inspection.id, "2026-11-28")).status).toBe(303); | |
| 38 | return { deal: await api(`/api/deals/${deal.id}`), id: inspection.id }; | |
| 39 | } | |
| 40 | ||
| 41 | test("the API flags an open date on a Saturday with the Monday, and a business day not at all", async () => { | |
| 42 | const { deal, id } = await dealWithSaturday(); | |
| 43 | expect(deal.deadlines.find((d) => d.id === id)!.nonBusinessDay).toEqual({ next: "2026-11-30" }); | |
| 44 | expect(deal.deadlines.find((d) => d.kind === "closing")!.nonBusinessDay).toBeNull(); // Tue, Dec 1 | |
| 45 | }); | |
| 46 | ||
| 47 | test("the page says so, and one tap moves it with its reason on record", async () => { | |
| 48 | const { deal, id } = await dealWithSaturday(); | |
| 49 | const page = await (await fetch(`${base}/deals/${deal.id}`, { headers: me })).text(); | |
| 50 | expect(page).toContain("Sat, Nov 28 · not a business day · next is Mon, Nov 30"); | |
| 51 | expect(page).toContain("Move to Mon, Nov 30"); | |
| 52 | const form = new RegExp(`<form method="post" action="/deadlines/${id}/move">([^]*?)</form>`).exec(page)![1]!; | |
| 53 | const body = new FormData(); | |
| 54 | for (const m of form.matchAll(/name="(\w+)" value="([^"]*)"/g)) body.set(m[1]!, m[2]!); | |
| 55 | const res = await fetch(`${base}/deadlines/${id}/move`, { method: "POST", body, headers: me, redirect: "manual" }); | |
| 56 | expect(res.status).toBe(303); | |
| 57 | const after = await api(`/api/deals/${deal.id}`); | |
| 58 | const inspection = after.deadlines.find((d) => d.id === id)!; | |
| 59 | expect(inspection.due).toBe("2026-11-30"); | |
| 60 | expect(inspection.nonBusinessDay).toBeNull(); | |
| 61 | expect(inspection.moves.at(-1)).toMatchObject({ reason: "Rolled to the next business day", to_due: "2026-11-30" }); | |
| 62 | }); | |
| 63 | ||
| 64 | test("MCP get_deal carries the flag", async () => { | |
| 65 | const { deal } = await dealWithSaturday(); | |
| 66 | const rpc = await fetch(base + "/mcp", { | |
| 67 | method: "POST", | |
| 68 | headers: json, | |
| 69 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "get_deal", arguments: { id: deal.id } } }), | |
| 70 | }); | |
| 71 | expect(JSON.stringify(await rpc.json())).toContain("nonBusinessDay"); | |
| 72 | }); | |
| 73 | ||
| 74 | test("This week marks the flagged date, on a pinned day", async () => { | |
| 75 | const { deal } = await dealWithSaturday(); | |
| 76 | const card = weekCard([deal], "2026-11-25"); | |
| 77 | expect(card).toContain("Not a business day · next is Mon, Nov 30"); | |
| 78 | }); |
src/pages/clock.ts +2 −2
| @@ -94,7 +94,7 @@ const dayHeading = (due: string, on: string): string => | ||
| 94 | 94 | const weekRows = memoizer<string>(3000); |
| 95 | 95 | |
| 96 | 96 | /** Open dates due within the week, under day headings; each row opens its sheet. */ |
| 97 | function weekCard(deals: readonly DealView[], on: string): string { | |
| 97 | export function weekCard(deals: readonly DealView[], on: string): string { | |
| 98 | 98 | const items = thisWeek(deals, on); |
| 99 | 99 | const groups: { heading: string; items: typeof items }[] = []; |
| 100 | 100 | for (const item of items) { |
| @@ -111,7 +111,7 @@ function weekCard(deals: readonly DealView[], on: string): string { | ||
| 111 | 111 | (g) => `<h3 class="week-day">${escape(g.heading)}</h3> |
| 112 | 112 | <ul class="week-list">${g.items |
| 113 | 113 | .map(({ deal, deadline: d }) => |
| 114 | weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}</b><small class="muted">${escape(deal.address)} · ${owedBy(deal, d)}</small></span>${badge(d, on)}</a></li>`), | |
| 114 | weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}</b><small class="muted">${escape(deal.address)} · ${owedBy(deal, d)}</small>${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}</span>${badge(d, on)}</a></li>`), | |
| 115 | 115 | ) |
| 116 | 116 | .join("")}</ul>`, |
| 117 | 117 | ) |
src/pages/deal.ts +2 −1
| @@ -16,7 +16,7 @@ import { partyContact } from "./contact.ts"; | ||
| 16 | 16 | import { confirmRemove } from "./confirm.ts"; |
| 17 | 17 | import { layout } from "./layout.ts"; |
| 18 | 18 | import { progressLine } from "./progress.ts"; |
| 19 | import { badge, conflictLines, draftItem, dueLine, outboxLine, owedBy, sheet, sheetId } from "./sheet.ts"; | |
| 19 | import { badge, conflictLines, nonBusinessLine, rollForm, draftItem, dueLine, outboxLine, owedBy, sheet, sheetId } from "./sheet.ts"; | |
| 20 | 20 | |
| 21 | 21 | const roleOptions = (selected?: string): string => |
| 22 | 22 | PARTY_ROLES.map( |
| @@ -112,6 +112,7 @@ export function dealPage(input: { | ||
| 112 | 112 | <p>${badge(d, on)} <b>${escape(d.label)}</b></p> |
| 113 | 113 | <p class="muted small">${escape(dueLine(d, on))}${d.moves.length > 0 ? ` · moved ${d.moves.length}×` : ""}</p> |
| 114 | 114 | <p class="small">${owedBy(deal, d)}</p> |
| 115 | ${nonBusinessLine(d)}${may ? rollForm(d, path) : ""} | |
| 115 | 116 | </div> |
| 116 | 117 | <button class="button button-quiet" popovertarget="${sheetId(d)}">Open</button> |
| 117 | 118 | </li>`, |
src/pages/sheet.ts +16 −1
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * script; the forms post and come back. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { BODY_MAX, canChange, REASON_MAX, SUBJECT_MAX, type DealView, type DeadlineView } from "../deals.ts"; | |
| 8 | import { BODY_MAX, canChange, ROLL_REASON, REASON_MAX, SUBJECT_MAX, type DealView, type DeadlineView } from "../deals.ts"; | |
| 9 | 9 | import { relative, short, spoken, urgency, type Urgency } from "../dates.ts"; |
| 10 | 10 | import { LEAD_MAX, LEAD_MIN, PARTY_LABEL } from "../deadlines.ts"; |
| 11 | 11 | import { escape } from "../http.ts"; |
| @@ -42,6 +42,20 @@ export function dueLine(d: DeadlineView, on: string): string { | ||
| 42 | 42 | return `Due ${spoken(d.due)} · ${relative(d.due, on)}`; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | /** "Sat, Nov 28 · not a business day · next is Mon, Nov 30" for a flagged date, else nothing. */ | |
| 46 | export const nonBusinessLine = (d: DeadlineView): string => | |
| 47 | d.nonBusinessDay === null | |
| 48 | ? "" | |
| 49 | : `<p class="conflict" role="note">${escape(spoken(d.due))} · not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</p>`; | |
| 50 | ||
| 51 | /** The one tap that moves a flagged date to its next business day, through the ordinary move. */ | |
| 52 | export const rollForm = (d: DeadlineView, to: string): string => | |
| 53 | d.nonBusinessDay === null | |
| 54 | ? "" | |
| 55 | : `<form method="post" action="/deadlines/${d.id}/move">${hidden({ to, due: d.nonBusinessDay.next, reason: ROLL_REASON })} | |
| 56 | <button class="button button-quiet">Move to ${escape(spoken(d.nonBusinessDay.next))}</button> | |
| 57 | </form>`; | |
| 58 | ||
| 45 | 59 | export const badge = (d: DeadlineView, on: string): string => { |
| 46 | 60 | const u = urgency(d.due, on, d.done_at !== null); |
| 47 | 61 | return `<span class="badge" data-u="${u}">${URGENCY_LABEL[u]}</span>`; |
| @@ -204,6 +218,7 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: | ||
| 204 | 218 | </header> |
| 205 | 219 | <section><h3>Who owes what</h3><p>${owedBy(deal, d)}</p>${d.what === "" ? "" : `<p>${escape(d.what)}</p>`}</section> |
| 206 | 220 | ${conflictLines(deal, d)} |
| 221 | ${nonBusinessLine(d)}${may ? rollForm(d, to) : ""} | |
| 207 | 222 | ${moves} |
| 208 | 223 | <section><h3>Reminders</h3>${d.done_at === null ? `<p class="muted">${remindsLine(d.lead_days)}</p>` : ""}${reminders}</section> |
| 209 | 224 | ${actions} |
src/routes.ts +5
| @@ -211,6 +211,11 @@ export const DEAL: Schema = { | ||
| 211 | 211 | what: { type: "string" }, |
| 212 | 212 | done_at: { type: ["string", "null"] }, |
| 213 | 213 | moves: { type: "array", items: { type: "object" } }, |
| 214 | nonBusinessDay: { | |
| 215 | type: ["object", "null"], | |
| 216 | description: "An open date due on a weekend or US federal holiday: next is the business day it rolls to. Null otherwise.", | |
| 217 | properties: { next: DATE }, | |
| 218 | }, | |
| 214 | 219 | }, |
| 215 | 220 | }, |
| 216 | 221 | }, |
src/terminal.test.ts +18
| @@ -704,3 +704,21 @@ test("L reads the audit trail in words for an admin, filters to messages and pag | ||
| 704 | 704 | press(guest, "L"); |
| 705 | 705 | expect(lines(guest).join("\n")).toContain("Sign in to read the audit trail."); |
| 706 | 706 | }); |
| 707 | ||
| 708 | test("a date on a weekend shows its next business day, and N rolls it there with the reason", () => { | |
| 709 | let saturday = addDays(today(), 400); | |
| 710 | while (new Date(`${saturday}T00:00:00Z`).getUTCDay() !== 6) saturday = addDays(saturday, 1); | |
| 711 | const monday = addDays(saturday, 2); | |
| 712 | const added = addDeadline(db, alice, { dealId: id, label: "Rate lock ends", due: saturday, owes: "buyer", what: "" }); | |
| 713 | expect(added.ok).toBe(true); | |
| 714 | const t = terminal(db, alice, context); | |
| 715 | goTo(t, "Rate lock ends — 12 Elm St"); | |
| 716 | expect(under(t)).toContain(`not a business day · next is ${spoken(monday)}`); | |
| 717 | t.press("N"); | |
| 718 | const rolled = deal().deadlines.find((d) => d.label === "Rate lock ends")!; | |
| 719 | expect(rolled.due).toBe(monday); | |
| 720 | expect(rolled.moves.at(-1)!.reason).toBe("Rolled to the next business day"); | |
| 721 | expect(under(t)).not.toContain("not a business day"); | |
| 722 | t.press("N"); | |
| 723 | expect(lines(t).join("\n")).toContain("already on a business day"); | |
| 724 | }); |
src/terminal.ts +17 −5
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | * deal one deal's dates and parties; a adds a date, p a party, A corrects the address, M amends the contract, S drafts a status update for the party under the cursor, D removes it |
| 14 | 14 | * |
| 15 | 15 | * On a date (dates or deal view): x marks it done, u reopens it, m moves it |
| 16 | * (a new date, then the reason), l sets how many days before it reminds. o or enter opens its deal; n opens a new | |
| 16 | * (a new date, then the reason), N moves one flagged "not a business day" to the next business day, l sets how many days before it reminds. o or enter opens its deal; n opens a new | |
| 17 | 17 | * deal (address, buyer, seller, contract and closing dates); d, r and b move |
| 18 | 18 | * between views; esc cancels a prompt; q leaves. / finds a deal by address or |
| 19 | 19 | * party and narrows dates, week and reminders to it; / then enter clears it. |
| @@ -51,6 +51,7 @@ import { | ||
| 51 | 51 | declineReminder, |
| 52 | 52 | undoDecline, |
| 53 | 53 | REASON_MAX, |
| 54 | ROLL_REASON, | |
| 54 | 55 | type DealView, |
| 55 | 56 | type DeadlineView, |
| 56 | 57 | } from "./deals.ts"; |
| @@ -179,7 +180,7 @@ export function terminal( | ||
| 179 | 180 | |
| 180 | 181 | function onDate(key: string): boolean { |
| 181 | 182 | const row = dateRows()[cursor]; |
| 182 | if (!["x", "u", "m", "l", "o", "\r"].includes(key)) return false; | |
| 183 | if (!["x", "u", "m", "N", "l", "o", "\r"].includes(key)) return false; | |
| 183 | 184 | if (row === undefined) { |
| 184 | 185 | said = "No date here."; |
| 185 | 186 | return true; |
| @@ -191,6 +192,16 @@ export function terminal( | ||
| 191 | 192 | ask(deal, [`New date for ${date.label} (YYYY-MM-DD, now ${date.due})`, "Why it moved"], ([due, reason]) => |
| 192 | 193 | report(moveDeadline(db, me, { id: date.id, due, reason }), () => withConflicts(db, me, deal.id, `Moved ${date.label} to ${isDate(due) ? spoken(due!) : due}; nothing else moved.`)), |
| 193 | 194 | ); |
| 195 | if (key === "N") { | |
| 196 | if (date.nonBusinessDay === null) said = `${date.label} is already on a business day.`; | |
| 197 | else if (!canChange(me, deal)) said = me.role === "anon" ? "Sign in to change a deal." : "You may not change this deal."; | |
| 198 | else { | |
| 199 | const next = date.nonBusinessDay.next; | |
| 200 | said = report(moveDeadline(db, me, { id: date.id, due: next, reason: ROLL_REASON }), () => | |
| 201 | withConflicts(db, me, deal.id, `Moved ${date.label} to ${spoken(next)}; nothing else moved.`), | |
| 202 | ); | |
| 203 | } | |
| 204 | } | |
| 194 | 205 | if (key === "l") |
| 195 | 206 | ask(deal, [`Remind how many days before ${date.label} (1 to 30, now ${date.lead_days})`], ([days]) => { |
| 196 | 207 | const set = setReminderLead(db, me, { id: date.id, leadDays: days }); |
| @@ -584,8 +595,9 @@ export function terminal( | ||
| 584 | 595 | const label = view === "week" ? `${date.label} — ${deal.address} · ${who.name ?? who.role}` : withDeal ? `${date.label} — ${deal.address}` : date.label; |
| 585 | 596 | const text = label + (deal.closed && withDeal ? dim(" (closed)") : ""); |
| 586 | 597 | const moved = date.moves.length > 0 ? dim(` moved: ${date.moves.at(-1)!.reason}`) : ""; |
| 598 | const flag = date.nonBusinessDay === null ? "" : dim(` not a business day · next is ${spoken(date.nonBusinessDay.next)} (N moves it)`); | |
| 587 | 599 | const lead = date.done_at === null ? dim(` reminds ${date.lead_days}d before`) : ""; |
| 588 | return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${lead}${moved}`; | |
| 600 | return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${flag}${lead}${moved}`; | |
| 589 | 601 | }; |
| 590 | 602 | |
| 591 | 603 | function screen(): string[] { |
| @@ -741,8 +753,8 @@ export function terminal( | ||
| 741 | 753 | : view === "timeline" |
| 742 | 754 | ? "b back to the deal · d dates · q quit" |
| 743 | 755 | : view === "deal" |
| 744 | ? "j/k move · t client timeline · s messages · x done · u reopen · m move · l remind lead · a add date · p add party · e edit party · A edit address · M amend the contract · S status update to the party · X remove date/party · D remove deal · b back · q quit" | |
| 745 | : `j/k move · x done · u reopen · m move · l lead · o open deal · n new deal · c check dates · / find · R restore samples · h ${showDone ? "hide" : "show"} done · w this week · r reminders · P people · I profile · L activity · q quit`; | |
| 756 | ? "j/k move · t client timeline · s messages · x done · u reopen · m move · N next business day · l remind lead · a add date · p add party · e edit party · A edit address · M amend the contract · S status update to the party · X remove date/party · D remove deal · b back · q quit" | |
| 757 | : `j/k move · x done · u reopen · m move · N next business day · l lead · o open deal · n new deal · c check dates · / find · R restore samples · h ${showDone ? "hide" : "show"} done · w this week · r reminders · P people · I profile · L activity · q quit`; | |
| 746 | 758 | lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys)); |
| 747 | 759 | } |
| 748 | 760 | return lines; |
new above
offline
The week row has this flag, but the terminal's week view (src/terminal.ts dateLine) does not. Add it there.