From 77922ae5db5f40b8e228337b56af44d7c98bafbc Mon Sep 17 00:00:00 2001 From: Michael Oliver Date: Mon, 4 Sep 2023 11:46:24 +0100 Subject: [PATCH] chore: use `z.coerce.date()` to pass input through `new Date(input)`. (#8383) --- examples/blog/src/content/config.ts | 10 ++-------- .../content-ssr-integration/src/content/config.ts | 7 ++----- .../src/content/config.ts | 7 ++----- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/examples/blog/src/content/config.ts b/examples/blog/src/content/config.ts index b4e86c9f7..f0419223e 100644 --- a/examples/blog/src/content/config.ts +++ b/examples/blog/src/content/config.ts @@ -6,14 +6,8 @@ const blog = defineCollection({ title: z.string(), description: z.string(), // Transform string to Date object - pubDate: z - .string() - .or(z.date()) - .transform((val) => new Date(val)), - updatedDate: z - .string() - .optional() - .transform((str) => (str ? new Date(str) : undefined)), + pubDate: z.coerce.date(), + updatedDate: z.coerce.date().optional(), heroImage: z.string().optional(), }), }); diff --git a/packages/astro/test/fixtures/content-ssr-integration/src/content/config.ts b/packages/astro/test/fixtures/content-ssr-integration/src/content/config.ts index d22a45648..8d68c0ec3 100644 --- a/packages/astro/test/fixtures/content-ssr-integration/src/content/config.ts +++ b/packages/astro/test/fixtures/content-ssr-integration/src/content/config.ts @@ -4,11 +4,8 @@ const blog = defineCollection({ schema: z.object({ title: z.string(), description: z.string(), - pubDate: z.string().transform((str) => new Date(str)), - updatedDate: z - .string() - .optional() - .transform((str) => (str ? new Date(str) : undefined)), + pubDate: z.coerce.date(), + updatedDate: z.coerce.date().optional(), heroImage: z.string().optional(), }), }); diff --git a/packages/astro/test/fixtures/content-static-paths-integration/src/content/config.ts b/packages/astro/test/fixtures/content-static-paths-integration/src/content/config.ts index d22a45648..8d68c0ec3 100644 --- a/packages/astro/test/fixtures/content-static-paths-integration/src/content/config.ts +++ b/packages/astro/test/fixtures/content-static-paths-integration/src/content/config.ts @@ -4,11 +4,8 @@ const blog = defineCollection({ schema: z.object({ title: z.string(), description: z.string(), - pubDate: z.string().transform((str) => new Date(str)), - updatedDate: z - .string() - .optional() - .transform((str) => (str ? new Date(str) : undefined)), + pubDate: z.coerce.date(), + updatedDate: z.coerce.date().optional(), heroImage: z.string().optional(), }), });