fix formatRelativeDate error handling; run [date] (#8497)

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
chris48s
2022-10-08 11:43:29 +01:00
committed by GitHub
parent d78a2f4155
commit 8f4662bd0b
2 changed files with 11 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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')
})
})
})