initial
This commit is contained in:
22
frontend/src/utils/date.ts
Normal file
22
frontend/src/utils/date.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { format, parseISO } from "date-fns";
|
||||
import { de } from "date-fns/locale";
|
||||
|
||||
export function formatDate(date: string | null | undefined, pattern = "dd.MM.yyyy"): string {
|
||||
if (!date) return "–";
|
||||
try {
|
||||
return format(parseISO(date), pattern, { locale: de });
|
||||
} catch {
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatDeadlineDate(date: string | null | undefined): string {
|
||||
return formatDate(date);
|
||||
}
|
||||
|
||||
export function formatCurrency(amount: number | null | undefined, currency = "EUR"): string {
|
||||
if (amount === null || amount === undefined) {
|
||||
return "–";
|
||||
}
|
||||
return new Intl.NumberFormat("de-DE", { style: "currency", currency }).format(amount);
|
||||
}
|
||||
Reference in New Issue
Block a user