Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: invalid date handling (#7422)

pengx175c1f78afd4cf
diff --git a/packages/frontend/i18n/src/utils/__tests__/time.spec.ts b/packages/frontend/i18n/src/utils/__tests__/time.spec.ts
index 651d44625b..44321a4b18 100644
--- a/packages/frontend/i18n/src/utils/__tests__/time.spec.ts
+++ b/packages/frontend/i18n/src/utils/__tests__/time.spec.ts
@@ -396,4 +396,9 @@ describe('humanTime', () => {
})
).toBe('本月');
});
+
+ test('invalid time', () => {
+ createI18n();
+ expect(i18nTime('foobar')).toBe('');
+ });
});
diff --git a/packages/frontend/i18n/src/utils/time.ts b/packages/frontend/i18n/src/utils/time.ts
index 4d7e015471..a1e3bae92e 100644
--- a/packages/frontend/i18n/src/utils/time.ts
+++ b/packages/frontend/i18n/src/utils/time.ts
@@ -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 = {