Skip to content
File

Blob: src/client/lib/format.ts

typescript14 lines
1const pad = (n: number): string => String(n).padStart(2, "0");
2 
3export const formatDate = (input: string | Date): string => {
4 const d = typeof input === "string" ? new Date(input) : input;
5 if (Number.isNaN(d.getTime())) return "—";
6 return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
7};
8 
9export const formatDateTime = (input: string | Date): string => {
10 const d = typeof input === "string" ? new Date(input) : input;
11 if (Number.isNaN(d.getTime())) return "—";
12 return `${formatDate(d)} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
13};