fix(server): prevent birthDate from shifting one day earlier on UTC+ servers

Replace toISOString().split('T')[0] with local getFullYear/getMonth/getDate
in asBirthDateString(). When the PostgreSQL DATE parser returns a local-
timezone Date (e.g. midnight in Europe/Istanbul), converting to ISO string
shifts the timestamp to UTC, which can roll the calendar date back by one
day for timezones ahead of UTC (fixes #28091).
pull/28715/head
Alexander Chen 2026-05-29 21:28:43 -07:00
parent c42cea5ca9
commit 6a560ef574
1 changed files with 9 additions and 1 deletions

View File

@ -17,7 +17,15 @@ export const asDateString = <T extends Date | string | undefined | null>(x: T) =
* @deprecated Remove this and all references when using `ZodSerializerDto` on the controllers. Then the codec in `isoDateToDate` in validation.ts will handle the conversion instead.
*/
export const asBirthDateString = (x: Date | string | null): string | null => {
return x instanceof Date ? x.toISOString().split('T')[0] : x;
if (x instanceof Date) {
// Use local date components to avoid UTC timezone shifts that can
// cause dates to appear one day earlier on servers ahead of UTC.
const year = x.getFullYear();
const month = String(x.getMonth() + 1).padStart(2, '0');
const day = String(x.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
return x;
};
export const extractTimeZone = (dateTimeOriginal?: string | null) => {