unfixing date for now
This commit is contained in:
parent
2ff196ff76
commit
5eb24fde8b
2 changed files with 15 additions and 7 deletions
|
@ -1,10 +1,8 @@
|
||||||
---
|
---
|
||||||
import { formattedDate, isoDate } from '~/lib/date';
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
date: Date;
|
date: string | Date;
|
||||||
showTime?: boolean;
|
showTime?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { date, showTime = false } = Astro.props;
|
const { date, showTime = false } = Astro.props;
|
||||||
|
|
||||||
if (!date) {
|
if (!date) {
|
||||||
|
@ -12,6 +10,16 @@ if (!date) {
|
||||||
return null;
|
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>
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
function checkDate(date: Date | string): Date {
|
// function checkDate(date: Date | string): Date {
|
||||||
if (typeof date === Date)
|
// if (typeof date === Date)
|
||||||
}
|
// }
|
||||||
|
|
||||||
export function formattedDate(date: Date, showTime: boolean): string {
|
export function formattedDate(date: Date, showTime: boolean): string {
|
||||||
const options: Intl.DateTimeFormatOptions = {
|
const options: Intl.DateTimeFormatOptions = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue