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
70
71
72
73
74
75
76
77
78
79
80
|
// @flow
/* eslint-env mocha */
import assert from 'power-assert'
import formatDuration from '.'
describe('formatDuration', () => {
it('formats full duration', () => {
assert(
formatDuration({
years: 2,
months: 9,
weeks: 1,
days: 7,
hours: 5,
minutes: 9,
seconds: 30
}) === '2 years 9 months 1 week 7 days 5 hours 9 minutes 30 seconds'
)
})
it('formats partial duration', () => {
assert(formatDuration({ months: 9, days: 2 }) === '9 months 2 days')
})
it('allows to customize the format', () => {
assert(
formatDuration(
{
years: 2,
months: 9,
weeks: 1,
days: 7,
hours: 5,
minutes: 9,
seconds: 30
},
{ format: ['months', 'weeks'] }
) === '9 months 1 week'
)
})
it('does not include zeros by default', () => {
assert(
formatDuration({
years: 0,
months: 0,
weeks: 1,
days: 0,
hours: 0,
minutes: 0,
seconds: 0
}) === '1 week'
)
})
it('allows to include zeros', () => {
assert(
formatDuration(
{
years: 0,
months: 0,
weeks: 1,
days: 0,
hours: 0,
minutes: 0,
seconds: 0
},
{ zero: true }
) === '0 years 0 months 1 week 0 days 0 hours 0 minutes 0 seconds'
)
})
it('allows to customize the delimiter', () => {
assert(
formatDuration({ months: 9, days: 2 }, { delimiter: ', ' }) ===
'9 months, 2 days'
)
})
})
|