Skip to content

Commit

Permalink
Make lightFormat throw RangeError if the time value is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jan 9, 2019
1 parent a31b612 commit d9f629a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lightFormat/index.js
Expand Up @@ -92,7 +92,7 @@ export default function lightFormat(dirtyDate, dirtyFormatStr) {
var originalDate = toDate(dirtyDate)

if (!isValid(originalDate)) {
return 'Invalid Date'
throw new RangeError('Invalid time value')
}

// Convert the date in system timezone to the same date in UTC+00:00 timezone.
Expand Down
7 changes: 5 additions & 2 deletions src/lightFormat/test.js
Expand Up @@ -109,8 +109,11 @@ describe('lightFormat', () => {
})
})

it("returns String('Invalid Date') if the date isn't valid", () => {
assert(lightFormat(new Date(NaN), 'MMMM d, yyyy') === 'Invalid Date')
it("throws RangeError if the date isn't valid", () => {
assert.throws(
lightFormat.bind(null, new Date(NaN), 'MMMM d, yyyy'),
RangeError
)
})

it('implicitly converts `formatString`', () => {
Expand Down

0 comments on commit d9f629a

Please sign in to comment.