- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/client/src/times.ts?format=json
24 linesFirst import 83% · pinch 17%Last change pinch in version 33, 2 versions changed it
1// When something happened, short and the same everywhere it's shown (abso
2// issue 124): "08:34 UTC" today, "Oct 7 21:10 UTC" before that.
4import { newsShown } from "./core.ts";
6const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
8export function shortWhen(time: number, now: number = Date.now()): string {
9 const t = new Date(time);
10 const hm = t.toISOString().slice(11, 16);
11 if (t.toISOString().slice(0, 10) === new Date(now).toISOString().slice(0, 10)) return `${hm} UTC`;
12 const year = t.getUTCFullYear() === new Date(now).getUTCFullYear() ? "" : ` ${t.getUTCFullYear()}`;
13 return `${MONTHS[t.getUTCMonth()]} ${t.getUTCDate()}${year} ${hm} UTC`;
14}
16/** When the reader first saw it: "seen 08:40 UTC", or "new" when this is the first time. */
17export function seenText(seen: number | null, now: number = Date.now()): string {
18 return seen === null ? "new" : `seen ${shortWhen(seen, now)}`;
19}
21/** A news item as shown, with its time: a tell's after who told it, any other at its end. */
22export function newsWithTime(text: string, at: number | null, now: number = Date.now()): string {
23 return newsShown(text, at === null ? undefined : shortWhen(at, now));
24}