Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions packages/zod/src/v4/classic/tests/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/zod/src/v4/core/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down