diff --git a/packages/rdx-ddd/src/value-objects/utc-date.ts b/packages/rdx-ddd/src/value-objects/utc-date.ts index ff0f1319..8d8cdcb8 100644 --- a/packages/rdx-ddd/src/value-objects/utc-date.ts +++ b/packages/rdx-ddd/src/value-objects/utc-date.ts @@ -42,6 +42,19 @@ export class UtcDate extends ValueObject { return Result.ok(new UtcDate({ value: isoDateString })); } + /** + * Creador estático: devuelve la fecha de HOY en UTC a medianoche (00:00:00Z). + * - Evita ambigüedades de zona horaria construyendo el ISO explícitamente. + */ + static today(): UtcDate { + const now = new Date(); + const y = now.getUTCFullYear(); + const m = String(now.getUTCMonth() + 1).padStart(2, "0"); + const d = String(now.getUTCDate()).padStart(2, "0"); + const iso = `${y}-${m}-${d}T00:00:00Z`; + return new UtcDate({ value: iso }); + } + getProps(): string { return this.props.value; } @@ -57,7 +70,7 @@ export class UtcDate extends ValueObject { * Devuelve la fecha en formato UTC sin hora (YYYY-MM-DD). */ toDateString(): string { - return this.date.toISOString().split("T")[0]; + return this.date.toISOString().split("T")[0] ?? ""; } toString() {