Skip to content

Commit 7076e00

Browse files
Sync public snapshot from freebuff-private
Source: CodebuffAI/freebuff-private@42d9d1db9a7b2895732d49ab7d6ce84162fc81d4
1 parent 40944d4 commit 7076e00

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

‎cli/src/utils/time-format.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { afterEach, describe, expect, test } from 'bun:test'
2+
import { setSystemTime } from 'bun:test'
3+
4+
import { formatResetTimeLong } from './time-format'
5+
6+
describe('formatResetTimeLong', () => {
7+
afterEach(() => {
8+
setSystemTime()
9+
})
10+
11+
test('returns empty string for null', () => {
12+
expect(formatResetTimeLong(null)).toBe('')
13+
})
14+
15+
test('formats a multi-day reset with remaining hours', () => {
16+
setSystemTime(new Date('2026-01-01T00:00:00.000Z'))
17+
const resetDate = new Date('2026-01-05T07:00:00.000Z')
18+
19+
expect(formatResetTimeLong(resetDate)).toBe('4d 7h')
20+
})
21+
22+
test('formats a whole number of days with no remaining hours', () => {
23+
setSystemTime(new Date('2026-01-01T00:00:00.000Z'))
24+
const resetDate = new Date('2026-01-03T00:00:00.000Z')
25+
26+
expect(formatResetTimeLong(resetDate)).toBe('2d')
27+
})
28+
29+
test('formats hours and minutes under a day away', () => {
30+
setSystemTime(new Date('2026-01-01T00:00:00.000Z'))
31+
const resetDate = new Date('2026-01-01T02:30:00.000Z')
32+
33+
expect(formatResetTimeLong(resetDate)).toBe('2h 30m')
34+
})
35+
36+
test('formats minutes only under an hour away', () => {
37+
setSystemTime(new Date('2026-01-01T00:00:00.000Z'))
38+
const resetDate = new Date('2026-01-01T00:15:00.000Z')
39+
40+
expect(formatResetTimeLong(resetDate)).toBe('15m')
41+
})
42+
43+
test('falls back to "now" for a date already in the past', () => {
44+
setSystemTime(new Date('2026-01-01T00:00:00.000Z'))
45+
const resetDate = new Date('2025-12-31T00:00:00.000Z')
46+
47+
expect(formatResetTimeLong(resetDate)).toBe('now')
48+
})
49+
50+
test('accepts an ISO string in addition to a Date', () => {
51+
setSystemTime(new Date('2026-01-01T00:00:00.000Z'))
52+
53+
expect(formatResetTimeLong('2026-01-01T01:00:00.000Z')).toBe('1h')
54+
})
55+
56+
test('falls back to "now" for an unparseable date string', () => {
57+
setSystemTime(new Date('2026-01-01T00:00:00.000Z'))
58+
59+
expect(formatResetTimeLong('not-a-date')).toBe('now')
60+
})
61+
})

0 commit comments

Comments
 (0)