Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { timeAgo } from './time.ts'
4
5describe('timeAgo', () => {
6 it('formats deltas into human buckets', () => {
7 const now = Math.floor(Date.now() / 1000)
8 expect(timeAgo(null, now)).toBe('never')
9 expect(timeAgo(now - 30, now)).toBe('30s ago')
10 expect(timeAgo(now - 600, now)).toBe('10m ago')
11 expect(timeAgo(now - 7200, now)).toBe('2h ago')
12 expect(timeAgo(now - 259_200, now)).toBe('3d ago')
13 })
14
15 it('measures from the given instant, not the clock, so SSR and hydration agree', () => {
16 // A server render and the later hydration pass the same `now`.
17 const renderedAt = 1_700_000_000
18 expect(timeAgo(renderedAt - 45, renderedAt)).toBe('45s ago')
19 })
20})