~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
26 lines · 1.1 KB Raw History
// `npm run unit` in web/ (`just check` runs it).
import { strict as assert } from 'node:assert';
import { test } from 'node:test';
import { formatShortTime } from './format.ts';

const now = Date.parse('2026-11-22T12:00:00Z');
const at = (seconds: number) => new Date(now + seconds * 1000).toISOString();

test('a short time is now under a minute either side of the clock', () => {
	assert.equal(formatShortTime(at(-30), now, true), 'now');
	assert.equal(formatShortTime(at(0), now, true), 'now');
	assert.equal(formatShortTime(at(5), now, true), 'now');
	assert.equal(formatShortTime(at(59), now, true), 'now');
});

test('a short time counts minutes, hours and days back', () => {
	assert.equal(formatShortTime(at(-5 * 60), now, true), '5m');
	assert.equal(formatShortTime(at(-3 * 3600), now, true), '3h');
	assert.equal(formatShortTime(at(-2 * 86_400), now, true), '2d');
});

test('a short time a minute or more ahead, or a week back, is the day', () => {
	assert.equal(formatShortTime(at(60), now, true), 'Nov 22');
	assert.equal(formatShortTime(at(-8 * 86_400), now, true), 'Nov 14');
	assert.equal(formatShortTime('no date', now, true), null);
});