- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/client/test/times.test.ts?format=json
53 linesFirst import 58% · pinch 38% · rename 4%Last change rename in version 100, 3 versions changed it
1// Times as abso shows them (abso issue 124): short, and the same everywhere.
3import assert from "node:assert/strict";
4import { test } from "node:test";
5import { newsWithTime, seenText, shortWhen } from "../src/times.ts";
7const now = Date.parse("2026-10-08T08:45:00Z");
9test("today's times are the hour and minute; earlier ones carry the date, and another year's the year", () => {
10 assert.equal(shortWhen(Date.parse("2026-10-08T08:34:59Z"), now), "08:34 UTC");
11 assert.equal(shortWhen(Date.parse("2026-10-07T21:10:00Z"), now), "Oct 7 21:10 UTC");
12 assert.equal(shortWhen(Date.parse("2025-12-31T23:59:00Z"), now), "Dec 31 2025 23:59 UTC");
13});
15test("seen says when, or new", () => {
16 assert.equal(seenText(null, now), "new");
17 assert.equal(seenText(Date.parse("2026-10-08T08:40:00Z"), now), "seen 08:40 UTC");
18});
20test("news carries its time after the who", () => {
21 const at = Date.parse("2026-10-08T08:34:00Z");
22 assert.equal(
23 newsWithTime("Announcement from ann (as claimed): Split api.ts", at, now),
24 "ann (as claimed) told you, 08:34 UTC:\nSplit api.ts",
25 );
26 assert.equal(
27 newsWithTime('Announcement from C (a person, signed in on the website, id cf-1): "hi"', at, now),
28 "C (a person) told you, 08:34 UTC:\nhi",
29 );
30 assert.equal(
31 newsWithTime("Announcement from ann (as claimed): Split api.ts", null, now),
32 "ann (as claimed) told you:\nSplit api.ts",
33 );
34 assert.equal(
35 newsWithTime('w1 pushed "x" (version 3), which changes a.txt line 2', at, now),
36 'w1 pushed "x" (version 3), which changes a.txt line 2 (08:34 UTC)',
37 );
38 assert.equal(newsWithTime("from before times", null, now), "from before times");
39});
41test("a tell is shown as who told you and how sure that is, with what was said below", () => {
42 const shown = (text: string) => newsWithTime(text, null, now);
43 assert.equal(shown("Announcement from ann (key k_0123abcd): Go"), "ann (checked) told you:\nGo");
44 assert.equal(shown("Announcement from ann (key k_0123abcd, box b7): Go"), "ann (checked, box b7) told you:\nGo");
45 assert.equal(shown("Announcement from ann (shared token): Go"), "ann (as claimed) told you:\nGo");
46 // A person's words are unquoted, line breaks and all; their id is left out.
47 const person = shown(
48 `Announcement from Robin Ash (a person, signed in on the website, id cf-9): ${JSON.stringify('Two\nlines "here"')}`,
49 );
50 assert.equal(person, 'Robin Ash (a person) told you:\nTwo\nlines "here"');
51 // Anything else that starts the same way is other news, shown as it is.
52 assert.equal(shown("Announcement from ann (made up): Go"), "Announcement from ann (made up): Go");
53});