Files
kazoottt-blog-v2/src/utils/date.ts
2025-02-05 15:27:29 +08:00

24 lines
593 B
TypeScript

import type { CollectionEntry } from "astro:content";
import { siteConfig } from "@/site.config";
export function getFormattedDate(
date: Date | undefined,
options?: Intl.DateTimeFormatOptions,
): string {
if (date === undefined) {
return "Invalid Date";
}
return new Intl.DateTimeFormat(siteConfig.date.locale, {
...(siteConfig.date.options as Intl.DateTimeFormatOptions),
...options,
}).format(date);
}
export function collectionDateSort(
a: CollectionEntry<"post" | "note">,
b: CollectionEntry<"post" | "note">,
) {
return b.data.date.getTime() - a.data.date.getTime();
}