This repository was archived by the owner on Sep 4, 2023. It is now read-only.
forked from jkroso/parse-duration
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
106 lines (81 loc) · 2.4 KB
/
test.js
File metadata and controls
106 lines (81 loc) · 2.4 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict'
let t = require('tape')
let parse = require('./')
let {ns, h, b, s, ms, d, y, m} = parse
t('ms, millisecond, milliseconds', t => {
t.equal(parse('100ms'), 100)
t.equal(parse('10millisecond'), 10)
t.equal(parse('20 milliseconds'), 20)
t.end()
})
t('s, sec, secs, second, seconds', t => {
t.equal(parse('2s'), 2000)
t.equal(parse('.5sec'), 500)
t.equal(parse('+0. secs'), 0)
t.equal(parse('-.2 second'), -200)
t.equal(parse('+1e-2seconds'), 10)
t.end()
})
t('m, min, mins, minute, minutes', t => {
t.equal(parse('.25m'), 15000)
t.equal(parse('1min'), 60000)
t.equal(parse('1 mins'), 60000)
t.equal(parse('1 minute'), 60000)
t.equal(parse('10 minutes'), 600000)
t.end()
})
t('h, hr, hrs, hour, hours', t => {
t.equal(parse('.5h'), 1800000)
t.equal(parse('.5hr'), 1800000)
t.equal(parse('.5hrs'), 1800000)
t.equal(parse('.5hour'), 1800000)
t.equal(parse('.5hours'), 1800000)
t.end()
})
t('d, day, days', t => {
t.equal(parse('1d'), 24*60*60*1000)
t.equal(parse('1day'), 24*60*60*1000)
t.equal(parse('1days'), 24*60*60*1000)
t.end()
})
t('w, wk, wks, week, weeks', t => {
t.equal(parse('1w'), 24*60*60*7*1000)
t.equal(parse('1wk'), 24*60*60*7*1000)
t.equal(parse('1wks'), 24*60*60*7*1000)
t.equal(parse('1week'), 24*60*60*7*1000)
t.equal(parse('1weeks'), 24*60*60*7*1000)
t.end()
})
t('b, month, months', t => {
t.equal(parse('1b'), 24*60*60*1000*365.25/12)
t.equal(parse('1month'), 24*60*60*1000*365.25/12)
t.equal(parse('1months'), 24*60*60*1000*365.25/12)
t.end()
})
t('y, yr, yrs, year, years', t => {
t.equal(parse('1y'), 24*60*60*1000*365.25)
t.equal(parse('1yr'), 24*60*60*1000*365.25)
t.equal(parse('1yrs'), 24*60*60*1000*365.25)
t.equal(parse('1year'), 24*60*60*1000*365.25)
t.equal(parse('1years'), 24*60*60*1000*365.25)
t.end()
})
t('μs, ns', t => {
t.equal(parse('1ns'), 1 / 1e6)
t.equal(parse('1μs'), 1 / 1000)
t.end()
})
t('combined', t => {
t.equal(parse('1hr 20mins'), 1 * h + 20 * m)
t.equal(parse('1 hr 20 mins'), 1 * h + 20 * m)
t.equal(parse('27,681 ns'), 27681 * ns)
t.equal(parse('running length: 1hour:20mins'), 1* h + 20 * m)
t.equal(parse('2hr -40mins'), 1 * h + 20 * m)
t.equal(parse('2e3s'), 2000 * s)
t.end()
})
t('edge cases', t => {
t.equal(parse('1y.2b.5days.12hours.34sec.20ms'), 1 * y + .2 * b + .5 * d + .12 * h + .34 * s + .20 * ms)
t.equal(parse('-1y.2b.5days 12hours,34sec,20ms'), -1*y + .2*b + .5*d + 12*h + 34*s + 20*ms)
t.end()
})