Skip to content

Commit

Permalink
Merge 66ed4f2 into 9797b47
Browse files Browse the repository at this point in the history
  • Loading branch information
prolink007 committed Sep 20, 2018
2 parents 9797b47 + 66ed4f2 commit 892d846
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function parseTimestring (string, returnUnit, opts) {

totalSeconds += getSeconds(value, unit, unitValues)
})
} else {
throw new Error(`The string [${string}] is invalid for timestring`)
}

if (returnUnit) {
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ describe('timestring', () => {
expect(() => timestring('1g')).to.throw(Error)
})

it('throws an error when no numbers are in the timestring', () => {
expect(() => timestring('asdf')).to.throw(Error)
})

it('throws an error when numbers tail the timestring', () => {
expect(() => timestring('asdf123')).to.throw(Error)
})

it('can parse a messy time string', () => {
expect(timestring('5 D a YS 4 h 2 0 mI nS')).to.equal(447600)
})
Expand Down

0 comments on commit 892d846

Please sign in to comment.