Skip to content

Commit

Permalink
Fixing ZodString::isDatetime. (#1678)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Dec 12, 2022
1 parent b3b0ecf commit 957b55b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions deno/lib/__tests__/string.test.ts
Expand Up @@ -192,16 +192,19 @@ test("trim", () => {

test("datetime", () => {
const a = z.string().datetime({});
expect(a.isDatetime()).toEqual(true);
expect(a.isDatetime).toEqual(true);

const b = z.string().datetime({ offset: true });
expect(b.isDatetime()).toEqual(true);
expect(b.isDatetime).toEqual(true);

const c = z.string().datetime({ precision: 3 });
expect(c.isDatetime()).toEqual(true);
expect(c.isDatetime).toEqual(true);

const d = z.string().datetime({ offset: true, precision: 0 });
expect(d.isDatetime()).toEqual(true);
expect(d.isDatetime).toEqual(true);

const { isDatetime } = z.string().datetime();
expect(isDatetime).toEqual(true);
});

test("datetime parsing", () => {
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/types.ts
Expand Up @@ -847,7 +847,7 @@ export class ZodString extends ZodType<string, ZodStringDef> {
checks: [...this._def.checks, { kind: "trim" }],
});

isDatetime() {
get isDatetime() {
return !!this._def.checks.find((ch) => ch.kind === "datetime");
}

Expand Down
11 changes: 7 additions & 4 deletions src/__tests__/string.test.ts
Expand Up @@ -191,16 +191,19 @@ test("trim", () => {

test("datetime", () => {
const a = z.string().datetime({});
expect(a.isDatetime()).toEqual(true);
expect(a.isDatetime).toEqual(true);

const b = z.string().datetime({ offset: true });
expect(b.isDatetime()).toEqual(true);
expect(b.isDatetime).toEqual(true);

const c = z.string().datetime({ precision: 3 });
expect(c.isDatetime()).toEqual(true);
expect(c.isDatetime).toEqual(true);

const d = z.string().datetime({ offset: true, precision: 0 });
expect(d.isDatetime()).toEqual(true);
expect(d.isDatetime).toEqual(true);

const { isDatetime } = z.string().datetime();
expect(isDatetime).toEqual(true);
});

test("datetime parsing", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Expand Up @@ -847,7 +847,7 @@ export class ZodString extends ZodType<string, ZodStringDef> {
checks: [...this._def.checks, { kind: "trim" }],
});

isDatetime() {
get isDatetime() {
return !!this._def.checks.find((ch) => ch.kind === "datetime");
}

Expand Down

0 comments on commit 957b55b

Please sign in to comment.