unfixing date for now

This commit is contained in:
Ivy Turner 2025-04-30 11:35:55 +01:00
parent 2ff196ff76
commit 5eb24fde8b
No known key found for this signature in database
2 changed files with 15 additions and 7 deletions

View file

@ -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();
---
<time datetime={isoDate(date)}>{formattedDate(date, showTime)}</time>
<time datetime={isoDate}>{formattedDate}</time>

View file

@ -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 = {