feat: centralizar formateo UTC con util canónica y adaptar web/ICS
Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>main
parent
21164194c0
commit
f4f7d95485
@ -0,0 +1,28 @@
|
|||||||
|
import { toIsoSqlUTC as coreToIsoSqlUTC } from '../../../../src/utils/datetime';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializa una fecha en UTC al formato SQL ISO "YYYY-MM-DD HH:MM:SS[.SSS]".
|
||||||
|
* Mantiene exactamente la semántica previa basada en toISOString().replace().
|
||||||
|
*/
|
||||||
|
export function toIsoSqlUTC(d: Date = new Date()): string {
|
||||||
|
return coreToIsoSqlUTC(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Devuelve YYYY-MM-DD en UTC (útil para consultas por rango de fecha).
|
||||||
|
*/
|
||||||
|
export function ymdUTC(date: Date): string {
|
||||||
|
const yyyy = String(date.getUTCFullYear()).padStart(4, '0');
|
||||||
|
const mm = String(date.getUTCMonth() + 1).padStart(2, '0');
|
||||||
|
const dd = String(date.getUTCDate()).padStart(2, '0');
|
||||||
|
return `${yyyy}-${mm}-${dd}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suma meses en UTC preservando día (ajustado por desbordes de fin de mes por el propio motor).
|
||||||
|
*/
|
||||||
|
export function addMonthsUTC(date: Date, months: number): Date {
|
||||||
|
const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
||||||
|
d.setUTCMonth(d.getUTCMonth() + months);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
export function toIsoSqlUTC(d: Date = new Date()): string {
|
||||||
|
return d.toISOString().replace('T', ' ').replace('Z', '');
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue