diff --git a/app/specs/router/spec.json b/app/specs/router/spec.json index 2be4d7d9..6815bd4e 100644 --- a/app/specs/router/spec.json +++ b/app/specs/router/spec.json @@ -685,9 +685,9 @@ "after": ", {$after} after the message it answers", "lead": ": {$lead}", "rhythm": ".input {$per :string}\n.match $per\n1 {{; they write about every {$every}}}\n* {{; they write about {$per} times every {$every}}}", - "when": ".input {$time :string}\n.input {$ago :string}\n.match $time $ago\n|| || {{{$day}}}\n|| * {{{$day} ({$ago})}}\n* || {{{$day} at {$time}}}\n* * {{{$day} at {$time} ({$ago})}}", + "when": ".input {$allDay :string}\n.input {$ago :string}\n.local $day = {$at :date fields=month-day-weekday length=medium}\n.local $time = {$at :time precision=minute}\n.match $allDay $ago\nyes || {{{$day}}}\nyes * {{{$day} ({$ago})}}\n* || {{{$day} at {$time}}}\n* * {{{$day} at {$time} ({$ago})}}", "kept": ".input {$when :string}\n.match $when\n|| {{Keep “{$what}” as a note?}}\n* {{Keep “{$what}” for {$when}?}}", - "now": "It is {$when}", + "now": "It is {$at :datetime dateFields=year-month-day-weekday dateLength=long timePrecision=minute}", "unmatched": "Nothing you hold mentions “{$what}”", "empty": "Nothing has arrived yet: connect your mail and calendar, or keep a note, and ask again", "help": "Ask about your day, a person, your mail, your calendar or your notes", diff --git a/app/src/PrismRealizability.lex.tex b/app/src/PrismRealizability.lex.tex index cff85dc6..1c6d827b 100644 --- a/app/src/PrismRealizability.lex.tex +++ b/app/src/PrismRealizability.lex.tex @@ -171,7 +171,7 @@ name: realizabilityRouter, parameters: [], result: RealizabilityDescriptor, - body: (record RealizabilityDescriptor {facet := 20, digest := 2746994410, identity := (record RealizabilityElement {have := 20, need := 1}), vocabulary := (record RealizabilityElement {have := 9, need := 9}), capability := (record RealizabilityElement {have := 4, need := 4}), interfaceSpec := (record RealizabilityElement {have := 5, need := 5}), composition := (record RealizabilityElement {have := 0, need := 0}), dynamics := (record RealizabilityElement {have := 14, need := 14}), fidelity := (record RealizabilityElement {have := 16, need := 16}), resources := (record RealizabilityElement {have := 1107, need := 44}), authority := (record RealizabilityElement {have := 14, need := 14}), evidence := (record RealizabilityElement {have := 15, need := 13}), projection := (record RealizabilityElement {have := 5, need := 5})}) + body: (record RealizabilityDescriptor {facet := 20, digest := 2513064876, identity := (record RealizabilityElement {have := 20, need := 1}), vocabulary := (record RealizabilityElement {have := 9, need := 9}), capability := (record RealizabilityElement {have := 4, need := 4}), interfaceSpec := (record RealizabilityElement {have := 5, need := 5}), composition := (record RealizabilityElement {have := 0, need := 0}), dynamics := (record RealizabilityElement {have := 14, need := 14}), fidelity := (record RealizabilityElement {have := 16, need := 16}), resources := (record RealizabilityElement {have := 1107, need := 44}), authority := (record RealizabilityElement {have := 14, need := 14}), evidence := (record RealizabilityElement {have := 15, need := 13}), projection := (record RealizabilityElement {have := 5, need := 5})}) } definition{ diff --git a/site/card.mjs b/site/card.mjs index c49c1e58..3e68f561 100644 --- a/site/card.mjs +++ b/site/card.mjs @@ -1363,7 +1363,6 @@ export default async function start({ app, reason, $ }) { // A turn is what was asked and what was said, together; one sentence per item, each on its own line. const node = element("div", { className: "pr-turn" }, element("p", { className: "pr-you", textContent: prompt }), element("p", { className: "pr-said", textContent: said.sentences.join("\n") })); chat.append(node); - node.scrollIntoView({ block: "nearest" }); const rows = said.sources.map(rowOf); drawn.replaceChildren(...rows); // The sentences link to the items they say; the list beneath holds all that was found. @@ -1390,6 +1389,8 @@ export default async function start({ app, reason, $ }) { return button; }).filter(Boolean); node.append(...(links.length ? [element("p", { className: "pr-sources" }, ...links)] : []), ...(offers.length ? [element("div", { className: "pr-offers" }, ...offers)] : [])); + // Shown once it is whole, so the decision it offers is in view with it. + node.scrollIntoView({ block: "nearest" }); } out.style.whiteSpace = "pre-line"; out.style.minWidth = "0"; diff --git a/site/router/answer.mjs b/site/router/answer.mjs index 98ea5ea6..2e5028e4 100644 --- a/site/router/answer.mjs +++ b/site/router/answer.mjs @@ -17,16 +17,16 @@ import * as pin from "../message/guest.mjs"; const S = PROVIDERS.sentence; const RANK = ["public", "internal", "confidential", "restricted"]; const higher = (a, b) => (RANK.indexOf(b) > RANK.indexOf(a) ? b : a); -const day = new Intl.DateTimeFormat(undefined, { weekday: "short", month: "short", day: "numeric" }); -const clock = new Intl.DateTimeFormat(undefined, { hour: "numeric", minute: "2-digit" }); // Every sentence is a Unicode MessageFormat 2 message of the sentence provider -// (app/specs/router/spec.json), formatted by the message guest (app/src/PrismMessage.lex.tex). +// (app/specs/router/spec.json), formatted by the message guest (app/src/PrismMessage.lex.tex), +// dates and times too: a part named `at` is an instant, said in the wall time this browser keeps then. const guest = new URL(pin.GUESTS.message.path, new URL("../message/guest.mjs", import.meta.url)); const format = await pin.openGuestSync(guest.protocol === "file:" ? await (await import("node:fs/promises")).readFile(guest) : new Uint8Array(await (await fetch(guest)).arrayBuffer()), pin.GUESTS.message.sha256); // A value longer than a sentence can carry is cut; the item it cites holds the rest. +const zone = (at) => { const m = -new Date(at).getTimezoneOffset(), a = Math.abs(m); return `${m < 0 ? "-" : "+"}${String(Math.trunc(a / 60)).padStart(2, "0")}:${String(a % 60).padStart(2, "0")}`; }; const cut = (value) => { const text = String(value ?? ""); return text.length > S.lead * 2 ? `${text.slice(0, S.lead * 2)}…` : text; }; function fill(key, parts = {}) { - const [errors, ...text] = format(`format\n${JSON.stringify({ src: S.frames[key], bidiIsolation: "none", params: Object.entries(parts).map(([name, value]) => ({ name, value: cut(value) })) })}`).split("\n"); + const [errors, ...text] = format(`format\n${JSON.stringify({ src: S.frames[key], bidiIsolation: "none", params: Object.entries(parts).map(([name, value]) => ({ name, value: cut(value) })), ...(parts.at ? { timeZone: zone(parts.at) } : {}) })}`).split("\n"); if (errors) throw Object.assign(new Error(`the ${key} sentence does not format: ${errors}`), { code: "message.format" }); return text.join("\n"); } @@ -35,13 +35,10 @@ function fill(key, parts = {}) { // a "now", also how far that is from it, in wall-time's own periods: "(in 2 days)". export function whenOf(at, allDay = false, now = null) { if (!at) return ""; - const date = new Date(at); - const ago = Number.isFinite(now) ? relativeOf(allDay ? new Date(date).setHours(12) : at, allDay ? new Date(now).setHours(12) : now) : ""; - return fill("when", { day: day.format(date), time: allDay ? "" : clock.format(date), ago }); + const ago = Number.isFinite(now) ? relativeOf(allDay ? new Date(at).setHours(12) : at, allDay ? new Date(now).setHours(12) : now) : ""; + return fill("when", { at: new Date(at).toISOString(), allDay: allDay ? "yes" : "", ago }); } -// What the browser's clock says now, as the person reads a date and a time. -const full = new Intl.DateTimeFormat(undefined, { dateStyle: "full", timeStyle: "short" }); const asksNow = (text, terms) => S.now.phrases.some((p) => text.toLowerCase().includes(p)) || (terms.length > 0 && terms.every((t) => S.now.words.includes(t))); const whatOf = (item) => item.title || (item.body ?? "").split("\n")[0] || ""; @@ -84,7 +81,7 @@ export async function answer(prompt, options) { // PrismAsk in LexLean), asked of the root guest: the page only carries it out. const request = [halted(), asksNow(text, termsOf(text)) ? "asked" : "not", keep ? "keeps" : "asks", mapped.intent ?? "fact", mapped.start != null ? "yes" : "no", held.length ? "some" : "none"]; const decided = (await line(`ask ${request.join(" ")}`)).trim(); - if (decided === "clock") return { sentences: [end(fill("now", { when: full.format(new Date(now)) }))], sources: [], offers: [], mapped }; + if (decided === "clock") return { sentences: [end(fill("now", { at: new Date(now).toISOString() }))], sources: [], offers: [], mapped }; if (decided === "keep") return { sentences: [keptSentence(text, mapped)], sources: [], offers: [{ kind: "keep" }], mapped }; if (decided === "look") { const asked = await answer(prompt, { ...options, keep: false }); diff --git a/site/router/table.mjs b/site/router/table.mjs index 0bae5e29..e02f598b 100644 --- a/site/router/table.mjs +++ b/site/router/table.mjs @@ -690,9 +690,9 @@ export const SPEC = { "after": ", {$after} after the message it answers", "lead": ": {$lead}", "rhythm": ".input {$per :string}\n.match $per\n1 {{; they write about every {$every}}}\n* {{; they write about {$per} times every {$every}}}", - "when": ".input {$time :string}\n.input {$ago :string}\n.match $time $ago\n|| || {{{$day}}}\n|| * {{{$day} ({$ago})}}\n* || {{{$day} at {$time}}}\n* * {{{$day} at {$time} ({$ago})}}", + "when": ".input {$allDay :string}\n.input {$ago :string}\n.local $day = {$at :date fields=month-day-weekday length=medium}\n.local $time = {$at :time precision=minute}\n.match $allDay $ago\nyes || {{{$day}}}\nyes * {{{$day} ({$ago})}}\n* || {{{$day} at {$time}}}\n* * {{{$day} at {$time} ({$ago})}}", "kept": ".input {$when :string}\n.match $when\n|| {{Keep “{$what}” as a note?}}\n* {{Keep “{$what}” for {$when}?}}", - "now": "It is {$when}", + "now": "It is {$at :datetime dateFields=year-month-day-weekday dateLength=long timePrecision=minute}", "unmatched": "Nothing you hold mentions “{$what}”", "empty": "Nothing has arrived yet: connect your mail and calendar, or keep a note, and ask again", "help": "Ask about your day, a person, your mail, your calendar or your notes", diff --git a/test/time/order.test.mjs b/test/time/order.test.mjs index dde10050..93933fa1 100644 --- a/test/time/order.test.mjs +++ b/test/time/order.test.mjs @@ -123,7 +123,8 @@ test("the chat answers from now: the time, how long ago, and a message's turn", for (const question of ["What time is it?", "what's the date", "What day is it today?"]) { const said = await ask(question); const full = new Intl.DateTimeFormat(undefined, { dateStyle: "full", timeStyle: "short" }).format(new Date(now)); - assert.deepEqual(said.sentences, [`It is ${full}.`], question); + // CLDR puts a narrow no-break space before AM and PM; V8 writes a plain one. + assert.deepEqual(said.sentences.map((s) => s.replace(/\u202f/gu, " ")), [`It is ${full}.`], question); assert.deepEqual(said.sources, [], "the time draws on nothing held"); } const item = read(reply);