diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-03 10:56:21 +0300 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-03 10:56:21 +0300 |
| commit | 456cf011b36de91c9936994b1fa45703adcd309b (patch) | |
| tree | 8e60daf998f731ac50d100fa490eaecae1168042 /src/utils/date.ts | |
Initial fork of chrismwilliams/astro-theme-cactus theme
Diffstat (limited to 'src/utils/date.ts')
| -rw-r--r-- | src/utils/date.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils/date.ts b/src/utils/date.ts new file mode 100644 index 0000000..fb943a5 --- /dev/null +++ b/src/utils/date.ts @@ -0,0 +1,23 @@ +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(); +} |
