Files
anouma/lib/format.ts
T

30 lines
944 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { formatBerlinDate, formatBerlinTime } from "@/lib/calendar/timezone";
/** Day + short month, e.g. { day: "15", month: "SEP" } — for the date badge on event cards. */
export function formatEventDateParts(iso: string) {
const date = new Date(iso);
return {
day: formatBerlinDate(date, { day: "2-digit" }),
month: formatBerlinDate(date, { month: "short" }).toUpperCase().replace(".", ""),
};
}
export function formatFullDate(iso: string) {
return formatBerlinDate(new Date(iso), {
weekday: "long",
day: "2-digit",
month: "long",
year: "numeric",
});
}
export function formatTime(iso: string) {
return formatBerlinTime(new Date(iso), { hour: "2-digit", minute: "2-digit" });
}
export function formatTimeRange(start?: string | null, end?: string | null) {
if (start && end) return `${formatTime(start)} – ${formatTime(end)} Uhr`;
if (start) return `${formatTime(start)} Uhr`;
return null;
}