Public: anyone can read this; the crew can change it.
Showings are booked and shown in the agent's own time zone, not UTC #66
Check · Review · Land · Live done — Landed and live in production.
mason/speed-to-lead:mason/64-showings-are-booked-and-shown-in-the-age → main 1 commit fork
8 files
changed +151
−44
README.md +3 −3
| @@ -54,7 +54,7 @@ what you see right after a restart. Do step 1 first. | ||
| 54 | 54 | works" and record it: he is in "Needs you" with a fresh green clock and an |
| 55 | 55 | answer drafted, and his upcoming follow-ups wait until you send it. |
| 56 | 56 | 7. Book a showing. Open **Marcus Lee** again, press "Book a showing", pick |
| 57 | a day and time later this week (UTC), type an address and book it. The | |
| 57 | a day and time later this week (in your time zone from the profile), type an address and book it. The | |
| 58 | 58 | history says "Showing booked", his row on the desk carries a *Showing* |
| 59 | 59 | badge, and his follow-up plan says which follow-ups wait until the day |
| 60 | 60 | after. Press "Cancel showing" and they return to their usual place. |
| @@ -264,7 +264,7 @@ the same permission as any change to a lead, and shows on the Activity page. | ||
| 264 | 264 | |
| 265 | 265 | **When a lead agrees to a showing.** "Saturday at 10 works": on an open lead, |
| 266 | 266 | press **Book a showing**, choose the date and time (in the future, at most 90 |
| 267 | days ahead, entered in UTC) and, if you like, the address (up to 200 | |
| 267 | days ahead, entered in your profile's time zone) and, if you like, the address (up to 200 | |
| 268 | 268 | characters). The history says it ("Showing booked · Sat 10:00 · 12 Example |
| 269 | 269 | St") and the lead's row on the desk carries a *Showing* badge. A lead has one |
| 270 | 270 | showing: booking again moves it, and **Cancel showing** removes it. While a |
| @@ -423,7 +423,7 @@ until you press a key on this screen: | ||
| 423 | 423 | delete, then `ctrl-d` to approve and send — or `esc` to send nothing. |
| 424 | 424 | - `q` marks the lead qualified, `x` lost. |
| 425 | 425 | - `b` books a showing (or moves the one it has) on an open lead: type the |
| 426 | time in UTC like `2026-11-07T10:00` and press enter, then the address (or | |
| 426 | time in your profile's time zone like `2026-11-07T10:00` and press enter, then the address (or | |
| 427 | 427 | nothing) and press enter. A refused time asks again. `u` cancels the showing. The lead's |
| 428 | 428 | screen and its desk row show the showing. |
| 429 | 429 | - `D` removes the lead (admins only; asks first). |
src/actions.ts +1 −1
| @@ -722,7 +722,7 @@ function booked( | ||
| 722 | 722 | if (CLOSED.includes(lead.state)) |
| 723 | 723 | return fail("invalid", "A qualified or lost lead has no showings: put it back first."); |
| 724 | 724 | const now = stamp(at); |
| 725 | const time = timeOf(input.when, Date.parse(now)); | |
| 725 | const time = timeOf(input.when, Date.parse(now), currentAgent(db).timeZone); | |
| 726 | 726 | if ("error" in time) return fail("invalid", time.error); |
| 727 | 727 | if (input.address !== undefined && input.address !== null && typeof input.address !== "string") |
| 728 | 728 | return fail("invalid", "An address is text."); |
src/mcp.ts +1 −1
| @@ -190,7 +190,7 @@ export const tools: readonly Tool[] = [ | ||
| 190 | 190 | type: "object", |
| 191 | 191 | properties: { |
| 192 | 192 | id: { type: "integer" }, |
| 193 | at: { type: "string", description: "ISO 8601, like 2026-11-07T10:00 (UTC)." }, | |
| 193 | at: { type: "string", description: "ISO 8601, like 2026-11-07T10:00, read in the agent's profile time zone unless it ends in Z or an offset." }, | |
| 194 | 194 | address: { type: "string", maxLength: MAX_ADDRESS }, |
| 195 | 195 | }, |
| 196 | 196 | required: ["id", "at"], |
src/pages/desk.ts +3 −3
| @@ -149,11 +149,11 @@ const EMPTY: Record<View, string> = { | ||
| 149 | 149 | const held = (lead: DeskLead, due: string): string => |
| 150 | 150 | lead.showing !== null && due < lead.showing.hold_until ? lead.showing.hold_until : due; |
| 151 | 151 | |
| 152 | const showingBadge = (lead: DeskLead, now: number): string => | |
| 152 | const showingBadge = (lead: DeskLead, now: number, zone: string): string => | |
| 153 | 153 | lead.showing === null || Date.parse(lead.showing.hold_until) <= now |
| 154 | 154 | ? "" |
| 155 | 155 | : `<span class="badge" data-showing title="Showing booked: follow-ups wait until the day after">${escape( |
| 156 | ["Showing", showingWhen(lead.showing.at, now), ...(lead.showing.address === "" ? [] : [lead.showing.address])].join(" · "), | |
| 156 | ["Showing", showingWhen(lead.showing.at, now, zone), ...(lead.showing.address === "" ? [] : [lead.showing.address])].join(" · "), | |
| 157 | 157 | )}</span>`; |
| 158 | 158 | |
| 159 | 159 | function status(lead: DeskLead, now: number, zone: string): string { |
| @@ -177,7 +177,7 @@ const row = (lead: DeskLead, now: number, zone: string): string => `<li> | ||
| 177 | 177 | <span class="lead-main"> |
| 178 | 178 | <span class="lead-name">${escape(lead.name)}</span>${noteLine(lead.note) === "" ? "" : ` |
| 179 | 179 | <span class="note-line">${escape(noteLine(lead.note))}</span>`} |
| 180 | <span class="tags">${source(lead)}${consent(lead)}${showingBadge(lead, now)}</span> | |
| 180 | <span class="tags">${source(lead)}${consent(lead)}${showingBadge(lead, now, zone)}</span> | |
| 181 | 181 | <span class="ask">${escape(lead.message)}</span> |
| 182 | 182 | ${status(lead, now, zone)} |
| 183 | 183 | </span> |
src/pages/lead.ts +6 −6
| @@ -8,7 +8,7 @@ import { callLine, MAX_NOTE, OUTCOME_LABEL, OUTCOMES } from "../calls.ts"; | ||
| 8 | 8 | import { channelFor, isAnswer, MAX_BODY } from "../drafts.ts"; |
| 9 | 9 | import { escape } from "../http.ts"; |
| 10 | 10 | import { handoff } from "../handoff.ts"; |
| 11 | import { MAX_ADDRESS, MAX_AHEAD_DAYS, showingLine, showingWhen } from "../showings.ts"; | |
| 11 | import { MAX_ADDRESS, MAX_AHEAD_DAYS, localInput, showingLine, showingWhen } from "../showings.ts"; | |
| 12 | 12 | import { elapsed, between } from "../clock.ts"; |
| 13 | 13 | import { goesLabel, isQuiet, nextOpening } from "../quiet.ts"; |
| 14 | 14 | import { answerSince, MAX_INBOUND, MAX_LEAD_NOTE, type LeadDetail, type Message, type NextLead } from "../leads.ts"; |
| @@ -143,7 +143,7 @@ export function leadPage(input: { | ||
| 143 | 143 | .map(({ ours: m, theirs: r, call: c, showing: sh }) => |
| 144 | 144 | sh !== undefined |
| 145 | 145 | ? `<li data-from="showing"> |
| 146 | <p class="meta">${escape(showingLine(sh, now))}</p> | |
| 146 | <p class="meta">${escape(showingLine(sh, now, agent.timeZone))}</p> | |
| 147 | 147 | </li>` |
| 148 | 148 | : c !== undefined |
| 149 | 149 | ? `<li data-from="call"> |
| @@ -170,7 +170,7 @@ export function leadPage(input: { | ||
| 170 | 170 | ? `<section class="card"><h2>Follow-up plan</h2><p class="muted">Day 1, 3, 7, 14 and 30 follow-ups are drafted the moment the first reply goes out.</p></section>` |
| 171 | 171 | : `<section class="card"><h2>Follow-up plan</h2>${ |
| 172 | 172 | cadence.some(waits) |
| 173 | ? `<p class="hint">Follow-ups due before the showing (${escape(showingWhen(lead.showing!.at, now))}) wait until the day after it, ${escape(day(lead.showing!.hold_until))}.</p>` | |
| 173 | ? `<p class="hint">Follow-ups due before the showing (${escape(showingWhen(lead.showing!.at, now, agent.timeZone))}) wait until the day after it, ${escape(day(lead.showing!.hold_until))}.</p>` | |
| 174 | 174 | : "" |
| 175 | 175 | }<ol class="plan">${cadence |
| 176 | 176 | .map( |
| @@ -239,14 +239,14 @@ export function leadPage(input: { | ||
| 239 | 239 | |
| 240 | 240 | const details = editDetails(lead, path, mayUpdate && !closed); |
| 241 | 241 | |
| 242 | const min = new Date(now).toISOString().slice(0, 16); | |
| 243 | const max = new Date(now + MAX_AHEAD_DAYS * 86_400_000).toISOString().slice(0, 16); | |
| 242 | const min = localInput(now, agent.timeZone); | |
| 243 | const max = localInput(now + MAX_AHEAD_DAYS * 86_400_000, agent.timeZone); | |
| 244 | 244 | const showing = |
| 245 | 245 | mayUpdate && !closed |
| 246 | 246 | ? `<details class="card add record" id="book-showing"${lead.showing === null ? "" : " open"}> |
| 247 | 247 | <summary>${lead.showing === null ? "Book a showing" : "Move the showing"}</summary> |
| 248 | 248 | <form class="stack" method="post" action="${path}/showing"> |
| 249 | <label>Date and time (UTC) <input class="input" type="datetime-local" name="at" required min="${min}" max="${max}"${lead.showing === null ? "" : ` value="${escape(lead.showing.at.slice(0, 16))}"`}></label> | |
| 249 | <label>Date and time (${escape(agent.timeZone)}) <input class="input" type="datetime-local" name="at" required min="${min}" max="${max}"${lead.showing === null ? "" : ` value="${escape(localInput(Date.parse(lead.showing.at), agent.timeZone))}"`}></label> | |
| 250 | 250 | <label>Address (optional) <input class="input" name="address" maxlength="${MAX_ADDRESS}" autocomplete="off"${lead.showing === null ? "" : ` value="${escape(lead.showing.address)}"`}></label> |
| 251 | 251 | <p class="hint">Follow-ups due before the showing wait until the day after it. Nothing is sent.</p> |
| 252 | 252 | <button class="button">${lead.showing === null ? "Book the showing" : "Move the showing"}</button> |
src/showings.test.ts +65 −11
| @@ -18,8 +18,9 @@ import { | ||
| 18 | 18 | turn, |
| 19 | 19 | } from "./actions.ts"; |
| 20 | 20 | import { openDb } from "./db.ts"; |
| 21 | import { currentAgent, storeAgent } from "./profile.ts"; | |
| 21 | 22 | import { serve } from "./server.ts"; |
| 22 | import { showingLine, timeOf } from "./showings.ts"; | |
| 23 | import { localInput, showingLine, showingWhen, timeOf } from "./showings.ts"; | |
| 23 | 24 | import { plain, terminal } from "./terminal.ts"; |
| 24 | 25 | import { sign } from "./who.ts"; |
| 25 | 26 | import type { Who } from "./who.ts"; |
| @@ -30,7 +31,12 @@ const T0 = new Date("2026-03-01T10:00:00Z"); | ||
| 30 | 31 | const DAY = 86_400_000; |
| 31 | 32 | const at = (days: number) => new Date(T0.getTime() + days * DAY); |
| 32 | 33 | |
| 33 | const fresh = () => openDb(mkdtempSync(join(tmpdir(), "app-showing-"))); | |
| 34 | /** A database whose agent keeps UTC, so a time typed without an offset is the instant it reads. */ | |
| 35 | const fresh = () => { | |
| 36 | const db = openDb(mkdtempSync(join(tmpdir(), "app-showing-"))); | |
| 37 | storeAgent(db, { ...currentAgent(db), timeZone: "UTC" }, "test", T0.toISOString()); | |
| 38 | return db; | |
| 39 | }; | |
| 34 | 40 | const value = <T>(r: { ok: boolean; value?: T; message?: string }): T => { |
| 35 | 41 | if (!r.ok) throw new Error(r.message); |
| 36 | 42 | return r.value as T; |
| @@ -65,22 +71,59 @@ const statuses = (db: ReturnType<typeof fresh>, id: number) => | ||
| 65 | 71 | |
| 66 | 72 | test("a time must be a real date, in the future, within 90 days", () => { |
| 67 | 73 | const now = T0.getTime(); |
| 68 | expect(timeOf("2026-03-07T10:00", now)).toEqual({ at: "2026-03-07T10:00:00.000Z" }); | |
| 69 | expect(timeOf("2026-03-07T10:00:00-08:00", now)).toEqual({ at: "2026-03-07T18:00:00.000Z" }); | |
| 74 | expect(timeOf("2026-03-07T10:00", now, "UTC")).toEqual({ at: "2026-03-07T10:00:00.000Z" }); | |
| 75 | expect(timeOf("2026-03-07T10:00:00-08:00", now, "UTC")).toEqual({ at: "2026-03-07T18:00:00.000Z" }); | |
| 70 | 76 | for (const bad of ["", "Saturday", "2026-02-30T10:00", "2026-03-07", "2026-13-01T10:00", 5, null, undefined]) |
| 71 | expect("error" in timeOf(bad, now)).toBe(true); | |
| 72 | expect("error" in timeOf("2026-03-01T09:00", now)).toBe(true); // past | |
| 73 | expect("error" in timeOf("2026-03-01T10:00", now)).toBe(true); // now is not ahead | |
| 74 | expect("error" in timeOf("2026-05-30T10:00", now)).toBe(false); // 90 days less a bit | |
| 75 | expect("error" in timeOf("2026-06-01T10:00", now)).toBe(true); // beyond 90 days | |
| 77 | expect("error" in timeOf(bad, now, "UTC")).toBe(true); | |
| 78 | expect("error" in timeOf("2026-03-01T09:00", now, "UTC")).toBe(true); // past | |
| 79 | expect("error" in timeOf("2026-03-01T10:00", now, "UTC")).toBe(true); // now is not ahead | |
| 80 | expect("error" in timeOf("2026-05-30T10:00", now, "UTC")).toBe(false); // 90 days less a bit | |
| 81 | expect("error" in timeOf("2026-06-01T10:00", now, "UTC")).toBe(true); // beyond 90 days | |
| 82 | }); | |
| 83 | ||
| 84 | test("a time with no offset is read in the agent's zone, and round-trips", () => { | |
| 85 | const now = Date.parse("2026-03-01T10:00:00Z"); | |
| 86 | // Chicago is UTC-6 in early March, UTC-5 after the 8th. | |
| 87 | expect(timeOf("2026-03-07T10:00", now, "America/Chicago")).toEqual({ at: "2026-03-07T16:00:00.000Z" }); | |
| 88 | expect(timeOf("2026-03-14T10:00", now, "America/Chicago")).toEqual({ at: "2026-03-14T15:00:00.000Z" }); | |
| 89 | const at = "2026-03-07T16:00:00.000Z"; | |
| 90 | expect(showingWhen(at, Date.parse(at) - DAY, "America/Chicago")).toBe("Sat 10:00"); | |
| 91 | expect(localInput(Date.parse(at), "America/Chicago")).toBe("2026-03-07T10:00"); | |
| 92 | expect(showingLine({ at, address: "" }, Date.parse(at) - DAY, "America/Chicago")).toBe("Showing booked · Sat 10:00"); | |
| 93 | }); | |
| 94 | ||
| 95 | test("daylight-saving changes: the offset is the one in force that day", () => { | |
| 96 | const now = Date.parse("2026-03-01T10:00:00Z"); | |
| 97 | // New York springs forward 2026-03-08 02:00 -> 03:00. | |
| 98 | expect(timeOf("2026-03-08T01:30", now, "America/New_York")).toEqual({ at: "2026-03-08T06:30:00.000Z" }); | |
| 99 | expect(timeOf("2026-03-08T03:30", now, "America/New_York")).toEqual({ at: "2026-03-08T07:30:00.000Z" }); | |
| 100 | expect("error" in timeOf("2026-03-08T02:30", now, "America/New_York")).toBe(true); // skipped | |
| 101 | // ...and falls back 2026-11-01 02:00 -> 01:00. | |
| 102 | const fall = Date.parse("2026-10-20T10:00:00Z"); | |
| 103 | expect(timeOf("2026-11-01T00:30", fall, "America/New_York")).toEqual({ at: "2026-11-01T04:30:00.000Z" }); | |
| 104 | expect(timeOf("2026-11-01T01:30", fall, "America/New_York")).toEqual({ at: "2026-11-01T05:30:00.000Z" }); // first pass | |
| 105 | expect(timeOf("2026-11-01T02:30", fall, "America/New_York")).toEqual({ at: "2026-11-01T07:30:00.000Z" }); | |
| 106 | }); | |
| 107 | ||
| 108 | test("an explicit offset is kept whatever the zone", () => { | |
| 109 | const now = Date.parse("2026-03-01T10:00:00Z"); | |
| 110 | expect(timeOf("2026-03-07T10:00:00Z", now, "America/Chicago")).toEqual({ at: "2026-03-07T10:00:00.000Z" }); | |
| 111 | expect(timeOf("2026-03-07T10:00:00+02:00", now, "America/Chicago")).toEqual({ at: "2026-03-07T08:00:00.000Z" }); | |
| 112 | }); | |
| 113 | ||
| 114 | test("the past and 90-day limits are judged on the instant in the agent's zone", () => { | |
| 115 | const now = Date.parse("2026-03-01T10:00:00Z"); // 04:00 in Chicago | |
| 116 | expect("error" in timeOf("2026-03-01T03:00", now, "America/Chicago")).toBe(true); | |
| 117 | expect("error" in timeOf("2026-03-01T05:00", now, "America/Chicago")).toBe(false); // 11:00Z is ahead in Chicago, past in Tokyo | |
| 118 | expect("error" in timeOf("2026-03-01T05:00", now, "Asia/Tokyo")).toBe(true); | |
| 76 | 119 | }); |
| 77 | 120 | |
| 78 | 121 | test("the history line reads 'Showing booked · Sat 10:00 · address'", () => { |
| 79 | 122 | const sat = new Date("2026-03-07T10:00:00Z"); |
| 80 | expect(showingLine({ at: sat.toISOString(), address: "12 Example St" }, sat.getTime() - DAY)).toBe( | |
| 123 | expect(showingLine({ at: sat.toISOString(), address: "12 Example St" }, sat.getTime() - DAY, "UTC")).toBe( | |
| 81 | 124 | "Showing booked · Sat 10:00 · 12 Example St", |
| 82 | 125 | ); |
| 83 | expect(showingLine({ at: sat.toISOString(), address: "" }, sat.getTime() - DAY)).toBe( | |
| 126 | expect(showingLine({ at: sat.toISOString(), address: "" }, sat.getTime() - DAY, "UTC")).toBe( | |
| 84 | 127 | "Showing booked · Sat 10:00", |
| 85 | 128 | ); |
| 86 | 129 | }); |
| @@ -343,3 +386,14 @@ test("/openapi.json and MCP carry it", async () => { | ||
| 343 | 386 | const off = await call("cancel_showing", { id }); |
| 344 | 387 | expect(JSON.parse(off.result.content[0]!.text).showing).toBeNull(); |
| 345 | 388 | }); |
| 389 | ||
| 390 | test("booking reads a time with no offset in the profile's zone, and holds follow-ups from that instant", () => { | |
| 391 | const db = fresh(); | |
| 392 | storeAgent(db, { ...currentAgent(db), timeZone: "America/Chicago" }, "test", T0.toISOString()); | |
| 393 | const id = answered(db); | |
| 394 | const booked = value(bookShowing(db, alice, { id, when: "2026-03-07T10:00" }, at(1))); | |
| 395 | expect(booked.showing?.at).toBe("2026-03-07T16:00:00.000Z"); | |
| 396 | expect(booked.showing?.hold_until).toBe("2026-03-08T16:00:00.000Z"); | |
| 397 | const explicit = value(bookShowing(db, alice, { id, when: "2026-03-07T10:00:00Z" }, at(1))); | |
| 398 | expect(explicit.showing?.at).toBe("2026-03-07T10:00:00.000Z"); | |
| 399 | }); |
src/showings.ts +68 −15
| @@ -23,14 +23,56 @@ export interface Showing { | ||
| 23 | 23 | readonly booked_at: string; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | /** The wall clock in `zone` at the instant `ms`, as minutes-since-epoch read as if UTC. */ | |
| 27 | function wallMinutes(ms: number, zone: string): number { | |
| 28 | const parts = new Intl.DateTimeFormat("en-US", { | |
| 29 | timeZone: zone, | |
| 30 | year: "numeric", | |
| 31 | month: "numeric", | |
| 32 | day: "numeric", | |
| 33 | hour: "numeric", | |
| 34 | minute: "numeric", | |
| 35 | hourCycle: "h23", | |
| 36 | }).formatToParts(ms); | |
| 37 | const n = (type: string): number => Number(parts.find((p) => p.type === type)?.value); | |
| 38 | return Date.UTC(n("year"), n("month") - 1, n("day"), n("hour"), n("minute")) / 60_000; | |
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * The instant at which the wall in `zone` reads that date and time, or null | |
| 43 | * when the clocks skip it (the hour lost in spring). When the clocks repeat | |
| 44 | * it (autumn), the first of the two. | |
| 45 | */ | |
| 46 | function instantIn( | |
| 47 | y: number, | |
| 48 | mo: number, | |
| 49 | d: number, | |
| 50 | h: number, | |
| 51 | mi: number, | |
| 52 | zone: string, | |
| 53 | ): number | null { | |
| 54 | const want = Date.UTC(y, mo - 1, d, h, mi) / 60_000; | |
| 55 | // The offset at each end of the day around it; the answer is under one of them. | |
| 56 | const offsets = [-1, 0, 1].map((k) => { | |
| 57 | const probe = (want + k * 1440) * 60_000; | |
| 58 | return wallMinutes(probe, zone) - probe / 60_000; | |
| 59 | }); | |
| 60 | const found = [...new Set(offsets)] | |
| 61 | .map((off) => (want - off) * 60_000) | |
| 62 | .filter((ms) => wallMinutes(ms, zone) === want); | |
| 63 | return found.length === 0 ? null : Math.min(...found); | |
| 64 | } | |
| 65 | ||
| 26 | 66 | /** |
| 27 | 67 | * A showing time from user text: an ISO instant, or `YYYY-MM-DDTHH:MM` as a |
| 28 | * date-and-time field sends it (read as UTC). Returns the instant as ISO, | |
| 29 | * or the reason it is refused: malformed, in the past, or beyond 90 days. | |
| 68 | * date-and-time field sends it, read on the wall clock of `zone`, the | |
| 69 | * agent's. An explicit `Z` or `+hh:mm` is honoured. Returns the instant as | |
| 70 | * ISO, or the reason it is refused: malformed, in the past, or beyond 90 days. | |
| 30 | 71 | */ |
| 31 | 72 | export function timeOf( |
| 32 | 73 | text: unknown, |
| 33 | 74 | now: number, |
| 75 | zone: string, | |
| 34 | 76 | ): { at: string } | { error: string } { |
| 35 | 77 | const bad = { error: "A showing time is a date and time, like 2026-11-07T10:00." }; |
| 36 | 78 | if (typeof text !== "string") return bad; |
| @@ -39,45 +81,56 @@ export function timeOf( | ||
| 39 | 81 | text.trim(), |
| 40 | 82 | ); |
| 41 | 83 | if (m === null) return bad; |
| 42 | const ms = Date.parse( | |
| 43 | `${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}:${m[6] ?? "00"}${m[7] ?? "Z"}`, | |
| 44 | ); | |
| 45 | if (Number.isNaN(ms)) return bad; | |
| 84 | const [y, mo, d, h, mi] = [+m[1]!, +m[2]!, +m[3]!, +m[4]!, +m[5]!]; | |
| 46 | 85 | // Date.parse rolls 02-30 over to March; a real date reads back as itself. |
| 47 | if (new Date(Date.UTC(+m[1]!, +m[2]! - 1, +m[3]!)).getUTCDate() !== +m[3]!) | |
| 48 | return bad; | |
| 86 | if (new Date(Date.UTC(y, mo - 1, d)).getUTCDate() !== d || h > 23 || mi > 59) return bad; | |
| 87 | let ms: number; | |
| 88 | if (m[7] === undefined) { | |
| 89 | const local = instantIn(y, mo, d, h, mi, zone); | |
| 90 | if (local === null) | |
| 91 | return { error: "The clocks skip that time on that day: pick another." }; | |
| 92 | ms = local + +(m[6] ?? 0) * 1000; | |
| 93 | } else { | |
| 94 | ms = Date.parse(`${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}:${m[6] ?? "00"}${m[7]}`); | |
| 95 | if (Number.isNaN(ms)) return bad; | |
| 96 | } | |
| 49 | 97 | if (ms <= now) return { error: "A showing is booked in the future." }; |
| 50 | 98 | if (ms > now + MAX_AHEAD_DAYS * DAY_MS) |
| 51 | 99 | return { error: `A showing is at most ${MAX_AHEAD_DAYS} days ahead.` }; |
| 52 | 100 | return { at: new Date(ms).toISOString() }; |
| 53 | 101 | } |
| 54 | 102 | |
| 103 | /** An instant as a date-and-time field takes it, `YYYY-MM-DDTHH:MM`, on the wall clock of `zone`. */ | |
| 104 | export const localInput = (ms: number, zone: string): string => | |
| 105 | new Date(wallMinutes(ms, zone) * 60_000).toISOString().slice(0, 16); | |
| 106 | ||
| 55 | 107 | /** When the follow-ups wait until: a day after the showing. */ |
| 56 | 108 | export const holdUntil = (at: string): string => |
| 57 | 109 | new Date(Date.parse(at) + DAY_MS).toISOString(); |
| 58 | 110 | |
| 59 | /** In UTC, as the form takes it: "Sat 10:00", or "Sat Dec 12 10:00" beyond the coming week. */ | |
| 60 | export function showingWhen(at: string, now = Date.now()): string { | |
| 111 | /** In `zone`, the agent's: "Sat 10:00", or "Sat Dec 12 10:00" beyond the coming week. */ | |
| 112 | export function showingWhen(at: string, now: number, zone: string): string { | |
| 61 | 113 | const d = new Date(at); |
| 62 | const wd = d.toLocaleDateString("en-US", { weekday: "short", timeZone: "UTC" }); | |
| 114 | const wd = d.toLocaleDateString("en-US", { weekday: "short", timeZone: zone }); | |
| 63 | 115 | const time = d.toLocaleTimeString("en-US", { |
| 64 | 116 | hour: "2-digit", |
| 65 | 117 | minute: "2-digit", |
| 66 | 118 | hourCycle: "h23", |
| 67 | timeZone: "UTC", | |
| 119 | timeZone: zone, | |
| 68 | 120 | }); |
| 69 | 121 | if (Math.abs(d.getTime() - now) < 6 * DAY_MS) return `${wd} ${time}`; |
| 70 | const date = d.toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: "UTC" }); | |
| 122 | const date = d.toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: zone }); | |
| 71 | 123 | return `${wd} ${date} ${time}`; |
| 72 | 124 | } |
| 73 | 125 | |
| 74 | 126 | /** "Showing booked · Sat 10:00 · 12 Example St". */ |
| 75 | 127 | export const showingLine = ( |
| 76 | 128 | s: Pick<Showing, "at" | "address">, |
| 77 | now = Date.now(), | |
| 129 | now: number, | |
| 130 | zone: string, | |
| 78 | 131 | ): string => |
| 79 | 132 | [ |
| 80 | 133 | "Showing booked", |
| 81 | showingWhen(s.at, now), | |
| 134 | showingWhen(s.at, now, zone), | |
| 82 | 135 | ...(s.address === "" ? [] : [s.address]), |
| 83 | 136 | ].join(" · "); |
src/terminal.ts +4 −4
| @@ -279,7 +279,7 @@ export function terminal( | ||
| 279 | 279 | const showing = |
| 280 | 280 | l.showing === null |
| 281 | 281 | ? "" |
| 282 | : dim(` · showing ${showingWhen(l.showing.at, now())}${l.showing.address === "" ? "" : ` ${clean(l.showing.address)}`}`); | |
| 282 | : dim(` · showing ${showingWhen(l.showing.at, now(), currentAgent(db).timeZone)}${l.showing.address === "" ? "" : ` ${clean(l.showing.address)}`}`); | |
| 283 | 283 | lines.push( |
| 284 | 284 | `${i === cursor ? "▸" : " "} ${clockOf(l)} ${i === cursor ? bold(name) : name} ${dim(SOURCE_LABEL[l.source].padEnd(12))} ${next}${showing}`, |
| 285 | 285 | ); |
| @@ -395,9 +395,9 @@ export function terminal( | ||
| 395 | 395 | } |
| 396 | 396 | if (l.showing !== null) |
| 397 | 397 | lines.push( |
| 398 | dim(clean(showingLine(l.showing, now()))), | |
| 398 | dim(clean(showingLine(l.showing, now(), currentAgent(db).timeZone))), | |
| 399 | 399 | ...(Date.parse(l.showing.hold_until) > now() |
| 400 | ? [dim(` Follow-ups due before it wait until ${l.showing.hold_until.slice(0, 16).replace("T", " ")} UTC.`)] | |
| 400 | ? [dim(` Follow-ups due before it wait until ${showingWhen(l.showing.hold_until, now(), currentAgent(db).timeZone)}.`)] | |
| 401 | 401 | : []), |
| 402 | 402 | ); |
| 403 | 403 | const sent = l.messages.filter((m) => m.status === "sent").length; |
| @@ -615,7 +615,7 @@ export function terminal( | ||
| 615 | 615 | bold(`A showing with ${clean(lead(view.id)?.name ?? "the lead")}`), |
| 616 | 616 | "", |
| 617 | 617 | view.step === 0 |
| 618 | ? `When (UTC, like 2026-11-07T10:00, at most 90 days ahead): ${clean(view.typed)}█` | |
| 618 | ? `When (your time zone, like 2026-11-07T10:00, at most 90 days ahead): ${clean(view.typed)}█` | |
| 619 | 619 | : `When: ${clean(view.when)}`, |
| 620 | 620 | ...(view.step === 1 ? [`Address (optional): ${clean(view.typed)}█`] : []), |
| 621 | 621 | "", |
new above
offline