fix(server): return bday in UTC instead of server-local time

This commit is contained in:
Luke Wass 2026-07-15 23:59:31 -05:00
parent d8ed7d7bb9
commit eeeed6851a
2 changed files with 14 additions and 4 deletions

View file

@ -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');
});

View file

@ -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' });