mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
fix(server): return bday in UTC instead of server-local time
This commit is contained in:
parent
d8ed7d7bb9
commit
eeeed6851a
2 changed files with 14 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { Settings } from 'luxon';
|
||||
import { asDateString, asDateTimeString } from 'src/utils/date';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
|
||||
describe('asDateString', () => {
|
||||
it('should return null for null input', () => {
|
||||
|
|
@ -10,11 +11,20 @@ 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
|
||||
afterEach(() => {
|
||||
Settings.defaultZone = 'system';
|
||||
});
|
||||
|
||||
it('should return the UTC calendar date', () => {
|
||||
const date = new Date('2000-01-15'); // parsed as UTC midnight, like a database `date` column
|
||||
expect(asDateString(date)).toBe('2000-01-15');
|
||||
});
|
||||
|
||||
it('should not shift the date when the server runs in a timezone behind UTC', () => {
|
||||
Settings.defaultZone = 'America/Chicago';
|
||||
expect(asDateString(new Date('1994-09-01'))).toBe('1994-09-01');
|
||||
});
|
||||
|
||||
it('should correctly pad years with a leading 0', () => {
|
||||
expect(asDateString(new Date('280-12-12'))).toBe('0280-12-12');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -164,7 +164,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' });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue