40 lines
866 B
TypeScript
40 lines
866 B
TypeScript
const time = new Intl.DateTimeFormat(undefined, {
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
});
|
|
const day = new Intl.DateTimeFormat(undefined, {
|
|
day: "numeric",
|
|
month: "short",
|
|
});
|
|
const full = new Intl.DateTimeFormat(undefined, {
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
month: "short",
|
|
year: "numeric",
|
|
});
|
|
|
|
export function formatTime(iso: string): string {
|
|
return time.format(new Date(iso));
|
|
}
|
|
|
|
export function formatDay(iso: string): string {
|
|
return day.format(new Date(iso));
|
|
}
|
|
|
|
export function formatFull(iso: string): string {
|
|
return full.format(new Date(iso));
|
|
}
|
|
|
|
export function formatListDate(iso: string | null): string {
|
|
if (!iso) {
|
|
return "";
|
|
}
|
|
const date = new Date(iso);
|
|
const now = new Date();
|
|
if (date.toDateString() === now.toDateString()) {
|
|
return time.format(date);
|
|
}
|
|
return day.format(date);
|
|
}
|