Skip to content

Commit

Permalink
fix formatRelativeDate error handling; run [date] (#8497)
Browse files Browse the repository at this point in the history
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
  • Loading branch information
chris48s and repo-ranger[bot] authored Oct 8, 2022
1 parent d78a2f4 commit 8f4662b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions services/text-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ function formatDate(d) {
}

function formatRelativeDate(timestamp) {
return dayjs()
.to(dayjs.unix(parseInt(timestamp, 10)))
.toLowerCase()
const parsedDate = dayjs.unix(parseInt(timestamp, 10))
if (!parsedDate.isValid()) {
return 'invalid date'
}
return dayjs().to(parsedDate).toLowerCase()
}

export {
Expand Down
6 changes: 6 additions & 0 deletions services/text-formatters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,11 @@ describe('Text formatters', function () {
.describe('when given the beginning of october')
.expect('a month ago')
})

test(formatRelativeDate, () => {
given(9999999999999)
.describe('when given invalid date')
.expect('invalid date')
})
})
})

0 comments on commit 8f4662b

Please sign in to comment.