From 3446fe8ff7a7ba5e5661cf815baa6077eb1e9997 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 8 Jun 2026 16:51:11 +0000 Subject: [PATCH] Omit the year from dateToReadable within the current year dateToReadable now formats current-year dates without the year (e.g. "June 8th") and includes it otherwise (e.g. "February 3rd, 2024"). This keeps the mention menu subtitle compact while the relative title shows "Today"/"Tomorrow". --- shared/utils/date.test.ts | 12 ++++++++++-- shared/utils/date.ts | 11 ++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/shared/utils/date.test.ts b/shared/utils/date.test.ts index 43b2ec5a68..3f45e2a68c 100644 --- a/shared/utils/date.test.ts +++ b/shared/utils/date.test.ts @@ -19,8 +19,16 @@ describe("toISODate / parseISODate", () => { }); describe("dateToReadable", () => { - it("formats an absolute, human-readable date", () => { - expect(dateToReadable("2024-02-03")).toBe("February 3rd, 2024"); + it("includes the year outside the current year", () => { + expect(dateToReadable("2020-02-03")).toBe("February 3rd, 2020"); + }); + + it("omits the year within the current year", () => { + const date = new Date(); + date.setMonth(date.getMonth() === 0 ? 6 : 0); + date.setDate(15); + const result = dateToReadable(toISODate(date)); + expect(result).not.toContain(`${date.getFullYear()}`); }); it("returns the original string when invalid", () => { diff --git a/shared/utils/date.ts b/shared/utils/date.ts index 5a70e584f7..ab79132978 100644 --- a/shared/utils/date.ts +++ b/shared/utils/date.ts @@ -328,8 +328,9 @@ export function parseISODate(iso: string): Date | null { /** * Formats a date mention's stored ISO value into an absolute, localized, - * human-readable label (e.g. "January 2nd, 2024"). Suitable for plaintext - * and markdown serialization where a stable, unambiguous value is required. + * human-readable label. The year is omitted within the current year (e.g. + * "January 2nd") and included otherwise (e.g. "February 3rd, 2024"). Suitable + * for plaintext and markdown serialization. * * @param iso The date-only ISO string. * @param language The user's language preference. @@ -343,7 +344,11 @@ export function dateToReadable( if (!date) { return iso; } - return format(date, "MMMM do, yyyy", { locale: dateLocale(language) }); + const locale = dateLocale(language); + if (isSameYear(date, new Date())) { + return format(date, "MMMM do", { locale }); + } + return format(date, "MMMM do, yyyy", { locale }); } /**