Skip to content

High performance self-hosted photo and video management solution.

fix(server): person birthdate timezone bug (#31901)

Jason Rasmussen4b1b1f8c2ab7
diff --git a/server/src/utils/date.spec.ts b/server/src/utils/date.spec.ts
index d24e24dcbc..1cffa91a12 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 3a90fd4cc3..519edadffc 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' });