From f3abf9fa407135bd7f28232a82b56f349f5602ee Mon Sep 17 00:00:00 2001 From: "immich-push-o-matic[bot]" <179150890+immich-push-o-matic[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2026 17:06:59 +0000 Subject: [PATCH] fix(server): person birthdate timezone bug (#31906) fix(server): person birthdate timezone bug (#31901) (cherry picked from commit 4b1b1f8c2ab70db165088d857906420b967a9241) Co-authored-by: Jason Rasmussen --- server/src/utils/date.spec.ts | 20 ++++++++++++++------ server/src/validation.ts | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/server/src/utils/date.spec.ts b/server/src/utils/date.spec.ts index d24e24dcb..1cffa91a1 100644 --- a/server/src/utils/date.spec.ts +++ b/server/src/utils/date.spec.ts @@ -1,7 +1,11 @@ -import { describe, expect, it } from 'vitest'; +import { afterEach, describe, expect, it, vi } from 'vitest'; import { asDateString, asDateTimeString, isLeapDayObserved } from 'src/utils/date.js'; describe('asDateString', () => { + afterEach(() => { + vi.unstubAllEnvs(); + }); + it('should return null for null input', () => { expect(asDateString(null)).toBeNull(); }); @@ -10,13 +14,17 @@ describe('asDateString', () => { expect(asDateString('2000-01-15')).toBe('2000-01-15'); }); - it('should return the local calendar date, not the UTC date', () => { - const date = new Date(2000, 0, 15); // 15 Jan 2000, local midnight - expect(asDateString(date)).toBe('2000-01-15'); - }); + // a `date` column is parsed as `new Date('YYYY-MM-DD')`, which is UTC midnight regardless of the server time zone + it.each(['UTC', 'America/Los_Angeles', 'America/New_York', 'Europe/Istanbul', 'Pacific/Kiritimati'])( + 'should return the UTC calendar date of a date column when the server time zone is %s', + (timeZone) => { + vi.stubEnv('TZ', timeZone); + expect(asDateString(new Date('2000-01-15'))).toBe('2000-01-15'); + }, + ); it('should correctly pad years with a leading 0', () => { - expect(asDateString(new Date('280-12-12'))).toBe('0280-12-12'); + expect(asDateString(new Date('0280-12-12'))).toBe('0280-12-12'); }); }); diff --git a/server/src/validation.ts b/server/src/validation.ts index 3a90fd4cc..519edadff 100644 --- a/server/src/validation.ts +++ b/server/src/validation.ts @@ -171,7 +171,7 @@ export const isoDateToDate = z z.date(), { decode: (isoString) => new Date(isoString), - encode: (date) => DateTime.fromJSDate(date).toFormat('yyyy-MM-dd'), + encode: (date) => DateTime.fromJSDate(date, { zone: 'utc' }).toFormat('yyyy-MM-dd'), }, ) .meta({ example: '2024-01-01' });