UtcDate.today()

This commit is contained in:
David Arranz 2025-11-05 18:16:27 +01:00
parent 4c891fb8c8
commit d55dee448b

View File

@ -42,6 +42,19 @@ export class UtcDate extends ValueObject<UtcDateProps> {
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<UtcDateProps> {
* 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() {