From 5eb24fde8b0bb48a617de31252fc82988f136058 Mon Sep 17 00:00:00 2001 From: Ivy Turner Date: Wed, 30 Apr 2025 11:35:55 +0100 Subject: [PATCH] unfixing date for now --- src/components/util/Date.astro | 16 ++++++++++++---- src/lib/date.ts | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/components/util/Date.astro b/src/components/util/Date.astro index e207be9..9e8592d 100644 --- a/src/components/util/Date.astro +++ b/src/components/util/Date.astro @@ -1,10 +1,8 @@ --- -import { formattedDate, isoDate } from '~/lib/date'; export interface Props { - date: Date; + date: string | Date; showTime?: boolean; } - const { date, showTime = false } = Astro.props; if (!date) { @@ -12,6 +10,16 @@ if (!date) { return null; } +const dateObj = typeof date === "string" ? new globalThis.Date(date) : date; +const options: Intl.DateTimeFormatOptions = { year: "numeric", month: "long", day: "numeric" }; + +if (showTime) { + options.hour = "2-digit"; + options.minute = "2-digit"; +} + +const formattedDate = dateObj.toLocaleString("en-GB", options); +const isoDate = dateObj.toISOString(); --- - + \ No newline at end of file diff --git a/src/lib/date.ts b/src/lib/date.ts index e75f0f8..2451380 100644 --- a/src/lib/date.ts +++ b/src/lib/date.ts @@ -1,7 +1,7 @@ -function checkDate(date: Date | string): Date { - if (typeof date === Date) -} +// function checkDate(date: Date | string): Date { +// if (typeof date === Date) +// } export function formattedDate(date: Date, showTime: boolean): string { const options: Intl.DateTimeFormatOptions = {