diff --git a/packages/zod/src/v4/classic/tests/date.test.ts b/packages/zod/src/v4/classic/tests/date.test.ts index e63302da4..8fa873606 100644 --- a/packages/zod/src/v4/classic/tests/date.test.ts +++ b/packages/zod/src/v4/classic/tests/date.test.ts @@ -2,9 +2,9 @@ import { expect, test } from "vitest"; import * as z from "zod/v4"; -const beforeBenchmarkDate = new Date(2022, 10, 4); -const benchmarkDate = new Date(2022, 10, 5); -const afterBenchmarkDate = new Date(2022, 10, 6); +const beforeBenchmarkDate = new Date(Date.UTC(2022, 10, 4)); +const benchmarkDate = new Date(Date.UTC(2022, 10, 5)); +const afterBenchmarkDate = new Date(Date.UTC(2022, 10, 6)); const minCheck = z.date().min(benchmarkDate); const maxCheck = z.date().max(benchmarkDate); @@ -17,9 +17,40 @@ test("passing validations", () => { maxCheck.parse(beforeBenchmarkDate); }); -test("failing validations", () => { - expect(() => minCheck.parse(beforeBenchmarkDate)).toThrow(); - expect(() => maxCheck.parse(afterBenchmarkDate)).toThrow(); +test("date min", () => { + const result = minCheck.safeParse(beforeBenchmarkDate); + + expect(result.success).toEqual(false); + expect(result.error!.issues).toMatchInlineSnapshot(` + [ + { + "code": "too_small", + "inclusive": true, + "message": "Too small: expected date to be >=1667606400000", + "minimum": 1667606400000, + "origin": "date", + "path": [], + }, + ] + `); +}); + +test("date max", () => { + const result = maxCheck.safeParse(afterBenchmarkDate); + + expect(result.success).toEqual(false); + expect(result.error!.issues).toMatchInlineSnapshot(` + [ + { + "code": "too_big", + "inclusive": true, + "maximum": 1667606400000, + "message": "Too big: expected date to be <=1667606400000", + "origin": "date", + "path": [], + }, + ] + `); }); test("min max getters", () => { diff --git a/packages/zod/src/v4/core/checks.ts b/packages/zod/src/v4/core/checks.ts index 8c5383b58..8c8bf6535 100644 --- a/packages/zod/src/v4/core/checks.ts +++ b/packages/zod/src/v4/core/checks.ts @@ -84,7 +84,7 @@ export const $ZodCheckLessThan: core.$constructor<$ZodCheckLessThan> = /*@__PURE payload.issues.push({ origin, code: "too_big", - maximum: def.value as number, + maximum: typeof def.value === "object" ? def.value.getTime() : def.value, input: payload.value, inclusive: def.inclusive, inst, @@ -135,7 +135,7 @@ export const $ZodCheckGreaterThan: core.$constructor<$ZodCheckGreaterThan> = /*@ payload.issues.push({ origin, code: "too_small", - minimum: def.value as number, + minimum: typeof def.value === "object" ? def.value.getTime() : def.value, input: payload.value, inclusive: def.inclusive, inst,