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 {