From 4feb3e5829ea38e67123a48a3b6894b8bc4a230f Mon Sep 17 00:00:00 2001 From: David Corbitt Date: Wed, 9 Aug 2023 01:22:04 -0700 Subject: [PATCH] Avoid adding extra day to usage statistics --- app/src/server/api/routers/dashboard.router.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/server/api/routers/dashboard.router.ts b/app/src/server/api/routers/dashboard.router.ts index b18e1c0..ac11dbb 100644 --- a/app/src/server/api/routers/dashboard.router.ts +++ b/app/src/server/api/routers/dashboard.router.ts @@ -8,6 +8,7 @@ export const dashboardRouter = createTRPCRouter({ stats: publicProcedure .input( z.object({ + // TODO: actually take startDate into account startDate: z.string().optional(), organizationId: z.string(), }), @@ -33,7 +34,11 @@ export const dashboardRouter = createTRPCRouter({ let originalDataIndex = periods.length - 1; // *SLAMS DOWN GLASS OF WHISKEY* timezones, amirite? - let dayToMatch = dayjs(input.startDate || new Date()).add(1, "day"); + let dayToMatch = dayjs(input.startDate || new Date()) + // Ensure that the initial date we're matching against is never before the first period + if (periods[originalDataIndex] && dayToMatch.isBefore(periods[originalDataIndex]?.period, "day")) { + dayToMatch = dayjs(periods[originalDataIndex]?.period); + } const backfilledPeriods: typeof periods = []; // Backfill from now to 14 days ago or the date of the first logged call, whichever is earlier