mirror of
https://github.com/immich-app/immich.git
synced 2026-09-30 13:23:21 +08:00
fix(server): person birthdate timezone bug (#31906)
fix(server): person birthdate timezone bug (#31901)
(cherry picked from commit 4b1b1f8c2a)
Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
co-authored by
Jason Rasmussen
parent
d9371946eb
commit
f3abf9fa40
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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' });
|
||||
|
||||
Reference in New Issue
Block a user