Skip to content

Commit

Permalink
Add format test
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Apr 22, 2020
1 parent a5e1223 commit dabdbf3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ function parse(str, format){
units = parse[units] || parse[units.toLowerCase().replace(/s$/, '')]
if (units) result = (result || 0) + parseFloat(n, 10) * units
})
return result / parse[format]

return result && (result / parse[format])
}
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ t('invalid', t => {

t.end()
})

t('format', t => {
t.equal(parse('1hr 20mins', 'm'), parse('1hr 20mins') / 1000 / 60)

t.end()
})

0 comments on commit dabdbf3

Please sign in to comment.