From 05a50a0ce0b5e88f652bfebe6824509be69e8247 Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:05:04 +0000 Subject: [PATCH] refactor(#54): Improve month string formatting for consistent sorting --- src/routes/(user)/credits/+page.server.ts | 2 +- src/routes/(user)/credits/+page.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/(user)/credits/+page.server.ts b/src/routes/(user)/credits/+page.server.ts index 5cbc43e..f781a0d 100644 --- a/src/routes/(user)/credits/+page.server.ts +++ b/src/routes/(user)/credits/+page.server.ts @@ -19,7 +19,7 @@ export async function load({ locals: { safeGetSession } }) { const monthlyAggregates = transactions.reduce((acc, transaction) => { const date = new Date(transaction.created_at); - const month = `${date.getFullYear()}-${date.getMonth() + 1}`; + const month = date.toISOString().substring(0, 7); // Returns YYYY-MM format if (!acc[month]) acc[month] = { credits_added: 0, credits_deducted: 0 }; diff --git a/src/routes/(user)/credits/+page.svelte b/src/routes/(user)/credits/+page.svelte index 1d3b8fd..ffafa94 100644 --- a/src/routes/(user)/credits/+page.svelte +++ b/src/routes/(user)/credits/+page.svelte @@ -19,7 +19,7 @@ const groupedTransactions = transactions.reduce((acc, transaction) => { const date = new Date(transaction.created_at); - const month = `${date.getFullYear()}-${date.getMonth() + 1}`; + const month = date.toISOString().substring(0, 7); // Returns YYYY-MM format if (!acc[month]) acc[month] = []; acc[month].push(transaction); return acc;