Skip to content

Commit

Permalink
Fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Jun 20, 2024
1 parent 1437dd5 commit 8eda8d3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 8eda8d3

Please sign in to comment.