Skip to content

Commit dabdbf3

Browse files
committed
Add format test
1 parent a5e1223 commit dabdbf3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ function parse(str, format){
6363
units = parse[units] || parse[units.toLowerCase().replace(/s$/, '')]
6464
if (units) result = (result || 0) + parseFloat(n, 10) * units
6565
})
66-
return result / parse[format]
66+
67+
return result && (result / parse[format])
6768
}

test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,9 @@ t('invalid', t => {
114114

115115
t.end()
116116
})
117+
118+
t('format', t => {
119+
t.equal(parse('1hr 20mins', 'm'), parse('1hr 20mins') / 1000 / 60)
120+
121+
t.end()
122+
})

0 commit comments

Comments
 (0)