From d9b783107f337cee8f58b7d752ec8273286bb3f2 Mon Sep 17 00:00:00 2001 From: icamarillo Date: Mon, 16 Feb 2026 09:26:43 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20Corregir=20filtro=20de=20fechas=20en=20a?= =?UTF-8?q?uditor=C3=ADa=20por=20zona=20horaria?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - El filtro usaba hora local que se convertía incorrectamente a UTC - Los registros de 'hoy' aparecían en 'ayer' por desfase horario - Ahora trabaja directamente en UTC para consistencia - Afecta todos los filtros: today, yesterday, last7days, last30days - Custom dates también parseados correctamente como UTC --- .../src/routes/audit/+page.svelte | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/frontend-internal/src/routes/audit/+page.svelte b/frontend-internal/src/routes/audit/+page.svelte index b4cf141..d790a7f 100644 --- a/frontend-internal/src/routes/audit/+page.svelte +++ b/frontend-internal/src/routes/audit/+page.svelte @@ -43,51 +43,49 @@ * Obtener fechas según el período seleccionado */ function getDateRangeForPeriod(): { from: string; to: string } { - const today = new Date(); - today.setHours(0, 0, 0, 0); + // Trabajar en UTC para evitar problemas de zona horaria + const now = new Date(); let from: Date; - let to: Date = new Date(); + let to: Date; switch (periodFilter) { case 'today': - from = new Date(today); - to = new Date(); - to.setHours(23, 59, 59, 999); + // Hoy desde las 00:00:00 hasta ahora en UTC + from = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 0, 0, 0)); + to = new Date(); // Ahora en UTC break; case 'yesterday': - from = new Date(today); - from.setDate(from.getDate() - 1); - to = new Date(today); - to.setSeconds(to.getSeconds() - 1); + // Ayer completo en UTC + from = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 1, 0, 0, 0)); + to = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 0, 0, 0)); break; case 'last7days': - from = new Date(today); - from.setDate(from.getDate() - 7); + // Últimos 7 días en UTC + from = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 7, 0, 0, 0)); to = new Date(); - to.setHours(23, 59, 59, 999); break; case 'last30days': - from = new Date(today); - from.setDate(from.getDate() - 30); + // Últimos 30 días en UTC + from = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 30, 0, 0, 0)); to = new Date(); - to.setHours(23, 59, 59, 999); break; case 'custom': - // Para fechas custom, parsear las fechas string y agregar hora + // Para fechas custom, parsear como UTC if (!customDateFrom || !customDateTo) { return { from: '', to: '' }; } - const fromDate = new Date(customDateFrom); - fromDate.setHours(0, 0, 0, 0); - const toDate = new Date(customDateTo); - toDate.setHours(23, 59, 59, 999); + const fromParts = customDateFrom.split('-').map(Number); + const toParts = customDateTo.split('-').map(Number); + from = new Date(Date.UTC(fromParts[0], fromParts[1] - 1, fromParts[2], 0, 0, 0)); + to = new Date(Date.UTC(toParts[0], toParts[1] - 1, toParts[2], 23, 59, 59)); return { - from: fromDate.toISOString(), - to: toDate.toISOString() + from: from.toISOString(), + to: to.toISOString() }; default: - from = new Date(today); + from = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 0, 0, 0)); + to = new Date(); } return {