git clone https://garage44.eu/jeroen/midas.git.. /web/src/lib/format.test.ts
import {expect, test} from 'bun:test'
import {ahead, span} from '@/lib/format'
test('a time to come reads as today, tomorrow or its day', () => {
const from = new Date(2026, 9, 29, 22, 0)
const at = (d: Date) => Math.floor(d.getTime() / 1000)
expect(ahead(at(new Date(2026, 9, 29, 23, 30)), from)).toStartWith('today ')
expect(ahead(at(new Date(2026, 9, 30, 9, 0)), from)).toStartWith('tomorrow ')
expect(ahead(at(new Date(2026, 9, 31, 9, 0)), from)).not.toMatch(/^(today|tomorrow)/)
})
test('a span reads as a clock would say it', () => {
expect(span(40)).toBe('now')
expect(span(420)).toBe('7m')
expect(span(3600)).toBe('1h')
expect(span(6840)).toBe('1h 54m')
expect(span(14 * 3600 + 1200)).toBe('14h')
expect(span(3 * 86400)).toBe('3d')
expect(span(null)).toBe('–')
})