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:
@@ -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 {
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user