From 95a30a660c229b5fe69399c8464b48f85bb012ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Fri, 23 May 2025 12:00:24 +0200 Subject: [PATCH] fix(api): ensure we use correct date format to get chart (export) --- apps/api/src/controllers/export.controller.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/api/src/controllers/export.controller.ts b/apps/api/src/controllers/export.controller.ts index 6c9a36ed..cbaa0608 100644 --- a/apps/api/src/controllers/export.controller.ts +++ b/apps/api/src/controllers/export.controller.ts @@ -3,12 +3,14 @@ import type { FastifyReply, FastifyRequest } from 'fastify'; import { z } from 'zod'; import { HttpError } from '@/utils/errors'; +import { DateTime } from '@openpanel/common'; import type { GetEventListOptions } from '@openpanel/db'; import { ClientType, db, getEventList, getEventsCountCached, + getSettingsForProject, } from '@openpanel/db'; import { getChart } from '@openpanel/trpc/src/routers/chart.helpers'; import { zChartEvent, zChartInput } from '@openpanel/validation'; @@ -176,10 +178,21 @@ export async function charts( } const projectId = await getProjectId(request, reply); + const { timezone } = await getSettingsForProject(projectId); const { events, ...rest } = query.data; return getChart({ ...rest, + startDate: rest.startDate + ? DateTime.fromISO(rest.startDate) + .setZone(timezone) + .toFormat('yyyy-MM-dd HH:mm:ss') + : undefined, + endDate: rest.endDate + ? DateTime.fromISO(rest.endDate) + .setZone(timezone) + .toFormat('yyyy-MM-dd HH:mm:ss') + : undefined, projectId, events: events.map((event) => ({ ...event,