starfleet-ui
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#6 · main · 2 min 01 s
0Étoiles
0Forks
0Issues
| 1 | import { expect, test } from 'bun:test'; |
| 2 | import { untilLabel } from './time'; |
| 3 | |
| 4 | const now = Date.parse('2026-11-06T12:00:00Z'); |
| 5 | const at = (sec: number) => new Date(now + sec * 1000).toISOString(); |
| 6 | |
| 7 | test('untilLabel picks the two most significant units', () => { |
| 8 | expect(untilLabel(at(38), now)).toBe('38s'); |
| 9 | expect(untilLabel(at(4 * 60 + 12), now)).toBe('4m 12s'); |
| 10 | expect(untilLabel(at(2 * 3600 + 5 * 60), now)).toBe('2h 05m'); |
| 11 | expect(untilLabel(at(3 * 86_400 + 7200), now)).toBe('3d 2h'); |
| 12 | }); |
| 13 | |
| 14 | test('untilLabel clamps the past to zero', () => { |
| 15 | expect(untilLabel(at(-60), now)).toBe('0s'); |
| 16 | }); |