fix: normalize postgres birth dates

This commit is contained in:
Jesse_Chen
2026-07-27 11:29:12 +08:00
parent a4bc9ae0c2
commit ce9f8fe1da
2 changed files with 14 additions and 1 deletions
@@ -13,7 +13,7 @@ import type {
} from "./birth-time-journey-service.ts";
const profileSchema = z.object({
birth_date: z.string(),
birth_date: z.union([z.string(), z.date().transform((value) => value.toISOString().slice(0, 10))]),
reported_birth_time: z.string().nullable().optional(),
birth_time_source: z.enum([
"hospital_record",
@@ -30,6 +30,19 @@ test("birth time profile adapter parses an exact hospital declaration", () => {
}
});
test("birth time profile adapter normalizes PostgreSQL date values", () => {
const assessment = parseBirthTimeProfile({
birth_date: new Date("1993-04-17T00:00:00.000Z"),
reported_birth_time: "08:16:00",
birth_time_source: "hospital_record",
uncertainty_before_minutes: 2,
uncertainty_after_minutes: 2,
...coordinates,
});
assert.equal(assessment.date, "1993-04-17");
});
test("birth time profile adapter parses a period without inventing a time", () => {
const assessment = parseBirthTimeProfile({
birth_date: "1993-04-17",