fix: invalid date handling (#7422)

fix AF-1049
This commit is contained in:
pengx17 2024-07-04 07:11:18 +00:00
parent d6ad7d566f
commit 5c1f78afd4
No known key found for this signature in database
GPG Key ID: 23F23D9E8B3971ED
2 changed files with 9 additions and 0 deletions

View File

@ -396,4 +396,9 @@ describe('humanTime', () => {
})
).toBe('本月');
});
test('invalid time', () => {
createI18n();
expect(i18nTime('foobar')).toBe('');
});
});

View File

@ -73,6 +73,10 @@ export function i18nTime(
) {
const i18n = options.i18n ?? I18n;
time = dayjs(time);
if (!time.isValid()) {
return ''; // invalid time, return empty string
}
const now = dayjs(options.now);
const defaultRelativeOption = {