mirror of
https://github.com/prdlk/website.git
synced 2026-08-03 01:41:53 +00:00
24 lines
607 B
TypeScript
24 lines
607 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.publishDate.getTime() - a.data.publishDate.getTime();
|
||
|
|
}
|