-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathformat-time.test.ts
69 lines (61 loc) · 2.89 KB
/
format-time.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import formatTime from "../src/format-time";
it("Doesn't replace the wrong thing", () => {
expect(formatTime(0, 'the time is hms!')).toBe('the time is hms!')
expect(formatTime(0, 'this %% hat m%akes sense')).toBe('this %% hat m%akes sense')
});
it("Can render short times", () => {
const d = 10
expect(formatTime(d, 'hms')).toBe('10')
expect(formatTime(d, 'hm')).toBe('1')
expect(formatTime(d, 'd')).toBe('1')
expect(formatTime(d, 'h')).toBe('1')
expect(formatTime(d, 'm')).toBe('1')
expect(formatTime(d, 's')).toBe('10')
expect(formatTime(d, 'the time is %hms!')).toBe('the time is 10!')
expect(formatTime(d, 'the time is %m!')).toBe('the time is 1!')
expect(formatTime(d, 'the time is %s!')).toBe('the time is 10!')
});
it("Can render longer times", () => {
const d = 100
expect(formatTime(d, 'hms')).toBe('1:40')
expect(formatTime(d, 'hm')).toBe('2')
expect(formatTime(d, 'd')).toBe('1')
expect(formatTime(d, 'h')).toBe('1')
expect(formatTime(d, 'm')).toBe('2')
expect(formatTime(d, 's')).toBe('100')
expect(formatTime(d, 'the time is %hms!')).toBe('the time is 1:40!')
expect(formatTime(d, 'the time is %hm!')).toBe('the time is 2!')
expect(formatTime(-d, 'hms')).toBe('-1:40')
expect(formatTime(-d, 'hm')).toBe('-1')
expect(formatTime(-d, 'd')).toBe('0')
});
it("Can render long times", () => {
const d = 10000
expect(formatTime(d, 'hms')).toBe('2:46:40')
expect(formatTime(d, 'hm')).toBe('2:47')
expect(formatTime(d, 'h')).toBe('3')
expect(formatTime(d, 'm')).toBe('167')
expect(formatTime(d, 's')).toBe('10000')
expect(formatTime(d, 'the time is %d days')).toBe('the time is 1 days')
expect(formatTime(d, 'the time is %h hours')).toBe('the time is 3 hours')
expect(formatTime(d, 'the time is %m minutes')).toBe('the time is 167 minutes')
expect(formatTime(d, 'the time is %s seconds')).toBe('the time is 10000 seconds')
expect(formatTime(d, 'the time is %D:%H:%M:%S')).toBe('the time is 0:2:46:40')
expect(formatTime(d, 'the time is %D:%HH:%MM:%SS')).toBe('the time is 0:02:46:40')
expect(formatTime(-d, 'hms')).toBe('-2:46:40')
expect(formatTime(-d, 'hm')).toBe('-2:46')
expect(formatTime(-d, 'h')).toBe('-2')
expect(formatTime(-d, 'm')).toBe('-166')
expect(formatTime(-d, 'the time is %d days')).toBe('the time is 0 days')
expect(formatTime(-d, 'the time is %m minutes')).toBe('the time is -166 minutes')
expect(formatTime(-d, 'the time is %D:%HH:%MM:%SS')).toBe('the time is -0:02:46:40')
expect(formatTime(-d, 'the time is %H:%MM:%SS')).toBe('the time is -2:46:40')
});
it('can render negative times', () => {
expect(formatTime(-30, 'hms')).toBe('-30')
expect(formatTime(-60, 'hms')).toBe('-1:00')
expect(formatTime(-90, 'hms')).toBe('-1:30')
});
it('can render tricky times', () => {
expect(formatTime(59 + 59*60 + 1*60*60, 'hm')).toBe('2:00')
});