ad0855902b
Phase 1 — Quick Wins: centralize formatMoney/formatCents, extract findUniqueOrThrow helper (19 routers), shared Prisma select constants, useInvalidatePlanningViews hook, status badge consolidation, composite DB indexes. Phase 2 — Timeline Split: extract TimelineContext, TimelineResourcePanel, TimelineProjectPanel; split 28-dep useMemo into 3 focused memos. TimelineView.tsx reduced from 1,903 to 538 lines. Phase 3 — Query Performance: server-side filtering for getEntriesView, remove availability from timeline resource select, SSE event debouncing (50ms batch window). Phase 4 — Estimate Workspace: extract 7 tab components and 3 editor components. EstimateWorkspaceClient 1,298→306 lines, EstimateWorkspaceDraftEditor 1,205→581 lines. Phase 5 — Package Cleanup: split commit-dispo-import-batch (1,112→573 lines), extract shared pagination helper with 11 tests. All tests pass: 209 API, 254 engine, 67 application. Co-Authored-By: claude-flow <ruv@ruv.net>
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
/**
|
|
* Format a date as dd/mm/yyyy for display in the UI.
|
|
* Input date inputs (type="date") still use yyyy-mm-dd — this is for rendered text only.
|
|
*/
|
|
export function formatDate(d: Date | string | null | undefined): string {
|
|
if (!d) return "";
|
|
return new Date(d).toLocaleDateString("en-GB"); // en-GB → dd/mm/yyyy
|
|
}
|
|
|
|
/**
|
|
* Format a date as "DD MMM" (e.g. "04 Mar") for compact timeline labels.
|
|
*/
|
|
export function formatDateShort(d: Date | string): string {
|
|
return new Date(d).toLocaleDateString("en-GB", { day: "2-digit", month: "short" });
|
|
}
|
|
|
|
/**
|
|
* Format a date as "MMM YY" (e.g. "Mar 26") for timeline month headers.
|
|
*/
|
|
export function formatMonthYear(d: Date | string): string {
|
|
return new Date(d).toLocaleDateString("en-GB", { month: "short", year: "2-digit" });
|
|
}
|
|
|
|
/**
|
|
* Format a date in long form (e.g. "4 March 2026") for descriptive contexts.
|
|
*/
|
|
export function formatDateLong(d: Date | string): string {
|
|
return new Date(d).toLocaleDateString("en-GB", { day: "numeric", month: "long", year: "numeric" });
|
|
}
|
|
|
|
/**
|
|
* Format integer cents as a currency string (e.g. "1.234 €").
|
|
* Defaults to EUR with no decimal places.
|
|
*/
|
|
export function formatMoney(cents: number | null | undefined, currency = "EUR"): string {
|
|
const value = (cents ?? 0) / 100;
|
|
return new Intl.NumberFormat("de-DE", { style: "currency", currency, maximumFractionDigits: 0 }).format(value);
|
|
}
|
|
|
|
/**
|
|
* Format integer cents as a plain decimal string (e.g. "12,34").
|
|
* Returns "-" for null/undefined.
|
|
*/
|
|
export function formatCents(cents: number | null | undefined): string {
|
|
if (cents == null) return "-";
|
|
return (cents / 100).toLocaleString("de-DE", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
}
|