datewise/app/lib/format.ts
metatroncubeswdev e56182e0e3 chore: initial Datewise app (rebranded from SlotSure prototype)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 20:06:49 -04:00

33 lines
1.3 KiB
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.

/** Shared display helpers for admin screens (browser-safe). */
export const money = (cents: number, currency = "CAD") =>
new Intl.NumberFormat("en-CA", { style: "currency", currency }).format(cents / 100);
export const niceDate = (d: string | null | undefined, long = false) =>
d
? new Date(`${d}T12:00:00Z`).toLocaleDateString("en-CA", {
weekday: long ? "long" : "short",
month: long ? "long" : "short",
day: "numeric",
timeZone: "UTC",
})
: "—";
export const t12 = (hhmm?: string | null) => {
if (!hhmm) return "";
const [h, m] = hhmm.split(":").map(Number);
return `${h % 12 || 12}${m ? `:${String(m).padStart(2, "0")}` : ""} ${h >= 12 ? "PM" : "AM"}`;
};
export const slotLabel = (s?: string | null, e?: string | null) => (s && e ? `${t12(s)} – ${t12(e)}` : "—");
export const STATUS_TONE: Record<string, "success" | "critical" | "neutral" | "info" | "warning"> = {
confirmed: "success",
needs_review: "critical",
cancelled: "neutral",
fulfilled: "info",
};
export const METHOD_LABEL: Record<string, string> = { pickup: "Pickup", delivery: "Delivery", shipping: "Shipping" };
export const rangesToText = (r?: { start: string; end: string }[]) => (r ?? []).map((x) => `${x.start}-${x.end}`).join(", ");