starshard/peafowl
Template
1
Fork 0
mirror of https://github.com/starshardstudio/peafowl.git synced 2024-11-23 13:34:20 +00:00
peafowl/_utils/date.ts

12 lines
510 B
TypeScript
Raw Normal View History

2024-06-16 11:49:13 +00:00
import { GlobalData } from "./site.ts";
export function formatDateIso(date: Date | null | undefined | ""): string {
date = new Date(date as any)
if (Number.isNaN(date.getDate())) return ""
2024-06-16 11:49:13 +00:00
return `${date.getFullYear().toString().padStart(4, "0")}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`
}
export function compareDate(a: GlobalData, b: GlobalData): number {
return new Date(a.date ?? 0).getTime() - new Date(b.date ?? 0).getTime()
}