From c36b2d8fdcbe91401d0788574bfbf5e716ef1b4f Mon Sep 17 00:00:00 2001 From: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> Date: Thu, 5 Nov 2026 02:15:26 +0530 Subject: [PATCH] perf: reuse the changelog calendar date formatter --- resources/js/lib/changelog.ts | 8 +++++--- tests/Unit/Changelog.test.ts | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/resources/js/lib/changelog.ts b/resources/js/lib/changelog.ts index a4df9a826..ae712a180 100644 --- a/resources/js/lib/changelog.ts +++ b/resources/js/lib/changelog.ts @@ -43,12 +43,14 @@ export function changelogDays( timeZone: string, ): ChangelogDay[] { const days: ChangelogDay[] = []; + const calendar = new Intl.DateTimeFormat('en-CA', { timeZone }); let seenAuthors = new Set(); for (const commit of commits) { - const date = new Date(commit.committed_at).toLocaleDateString('en-CA', { - timeZone, - }); + const parsed = new Date(commit.committed_at); + const date = Number.isNaN(parsed.getTime()) + ? 'Invalid Date' + : calendar.format(parsed); let day = days.at(-1); if (day?.date !== date) { diff --git a/tests/Unit/Changelog.test.ts b/tests/Unit/Changelog.test.ts index b8b7d7542..87f6a96b6 100644 --- a/tests/Unit/Changelog.test.ts +++ b/tests/Unit/Changelog.test.ts @@ -105,3 +105,12 @@ void test('keeps the first author occurrence even for many commits on the same d assert.equal(days[0].commits.length, 200); assert.deepEqual(days[0].authors.map(({ login }) => login), ['alice', 'bob']); }); + +void test('keeps grouping when a commit has an invalid timestamp', () => { + const days = changelogDays( + [commit(1, 'not-a-date', 'alice'), commit(2, '2026-10-18T03:30:00Z', 'bob')], + 'Europe/Budapest', + ); + + assert.deepEqual(days.map((day) => day.date), ['Invalid Date', '2026-10-18']); +});