fix(sat-client): format dates in Mexico City timezone for SAT

formatDateForSat now uses Intl.DateTimeFormat with America/Mexico_City
timezone instead of UTC local time. Fixes 'Fecha final invalida' errors
when server runs in UTC and SAT interprets dates as Mexico local time.
This commit is contained in:
Horux Dev
2026-04-30 04:31:40 +00:00
parent 746d00bb66
commit 4e1a100b2a

View File

@@ -239,10 +239,23 @@ export async function downloadSatPackage(
} }
/** /**
* Formatea una fecha para el SAT (YYYY-MM-DD HH:mm:ss) * Formatea una fecha para el SAT (YYYY-MM-DD HH:mm:ss) en hora de México.
* El SAT opera en zona horaria America/Mexico_City (UTC-6 estándar).
*/ */
function formatDateForSat(date: Date): string { function formatDateForSat(date: Date): string {
const pad = (n: number) => n.toString().padStart(2, '0'); const pad = (n: string) => n.padStart(2, '0');
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` + const parts = new Intl.DateTimeFormat('en-US', {
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`; timeZone: 'America/Mexico_City',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
}).formatToParts(date);
const get = (type: string) => pad(parts.find(p => p.type === type)?.value || '00');
return `${get('year')}-${get('month')}-${get('day')} ${get('hour')}:${get('minute')}:${get('second')}`;
} }