- Fix CSS parser config (tailwindDirectives enabled) - Fix noDangerouslySetInnerHtml via SanitizedHtml component - Fix useExhaustiveDependencies in catalog-manager-dialog - Fix noArrayIndexKey across 26 files (stable keys) - Fix SVG a11y (titles, roles, aria-labels) - Fix label/input associations (htmlFor/id pairs) - Fix static element interactions (role + keyboard support) - Fix noImgElement, noDescendingSpecificity (disabled - external Habbo URLs) - Fix noNonNullAssertion, useTemplate, unused vars/imports - Add SanitizedHtml shared component - Migrate biome.json to 2.5.4 schema
36 lines
973 B
TypeScript
36 lines
973 B
TypeScript
export type DateFormatVariant = "date" | "datetime" | "datetime-seconds";
|
|
|
|
const FALLBACKS: Record<DateFormatVariant, string> = {
|
|
date: "",
|
|
datetime: "—",
|
|
"datetime-seconds": "—",
|
|
};
|
|
|
|
/**
|
|
* Format a Date for display. Kept as a single shared helper so the various
|
|
* admin/site pages no longer each redefine their own copy.
|
|
*
|
|
* - "date" → 2026-07-18
|
|
* - "datetime" → 2026-07-18 18:30
|
|
* - "datetime-seconds"→ 2026-07-18 18:30:45
|
|
*
|
|
* `fallback` overrides the default em-dash / empty string when the value is
|
|
* null/undefined.
|
|
*/
|
|
export function formatDate(
|
|
d: Date | null | undefined,
|
|
variant: DateFormatVariant = "datetime",
|
|
fallback?: string,
|
|
): string {
|
|
if (!d) return fallback ?? FALLBACKS[variant];
|
|
const iso = d.toISOString();
|
|
switch (variant) {
|
|
case "date":
|
|
return iso.slice(0, 10);
|
|
case "datetime-seconds":
|
|
return iso.slice(0, 19).replace("T", " ");
|
|
default:
|
|
return iso.slice(0, 16).replace("T", " ");
|
|
}
|
|
}
|