From 8eda8d3c849c01b5f3c79662afaf004e434d61b1 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 20 Jun 2024 18:25:51 +0100 Subject: [PATCH] Fixed test --- packages/utils/time.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/utils/time.ts b/packages/utils/time.ts index c7b5a3756c..59bd8bb564 100644 --- a/packages/utils/time.ts +++ b/packages/utils/time.ts @@ -91,7 +91,14 @@ export function timerPop() { export const formatMsToRelative = (ms: number) => { if (Date.now() - ms > 2 * Day) return formatMsToLocal(ms); - return dayjs(ms).fromNow(false); + const d = dayjs(ms); + + // The expected pattern for invalid date formatting in JS is to return the string "Invalid + // Date", so we do that here. If we don't, dayjs will process the invalid date and return "a + // month ago", somehow... + if (!d.isValid()) return 'Invalid Date'; + + return d.fromNow(false); }; const joplinLocaleToDayJsLocale = (locale: string) => {