summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Michael Oliver <michaeloliver__@outlook.com> 2023-09-04 11:46:24 +0100
committerGravatar GitHub <noreply@github.com> 2023-09-04 18:46:24 +0800
commit77922ae5db5f40b8e228337b56af44d7c98bafbc (patch)
tree04e9cc776addfb9423ae2c2768615a1d9b304376
parent535a4589998041cf2e3dfcac462a51479c1d13a3 (diff)
downloadastro-77922ae5db5f40b8e228337b56af44d7c98bafbc.tar.gz
astro-77922ae5db5f40b8e228337b56af44d7c98bafbc.tar.zst
astro-77922ae5db5f40b8e228337b56af44d7c98bafbc.zip
chore: use `z.coerce.date()` to pass input through `new Date(input)`. (#8383)
-rw-r--r--examples/blog/src/content/config.ts10
-rw-r--r--packages/astro/test/fixtures/content-ssr-integration/src/content/config.ts7
-rw-r--r--packages/astro/test/fixtures/content-static-paths-integration/src/content/config.ts7
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(),
}),
});