import { calendarDateInZone, viewerTimeZone } from '../../utils/practiceTimezone'; // The server's day is a UTC calendar day; its instant, when sent, is shown on the given clock (billing passes the // practice's), else the viewer's. A day alone is parsed as a local calendar day, never a UTC instant. export const chargeDateLabel = (day: string, instant?: string | null, timeZone?: string): string => { const options: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'long', year: 'numeric' }; const at = instant ? new Date(instant) : null; if (at && !Number.isNaN(at.getTime())) return at.toLocaleDateString(undefined, { ...options, timeZone }); return new Date(`${day}T00:00:00`).toLocaleDateString(undefined, options); }; /** The day `chargeDateLabel` names, as `YYYY-MM-DD`, for a page that formats its dates its own way. */ export const chargeDay = (day: string, instant?: string | null, timeZone?: string): string => { const at = instant ? new Date(instant) : null; if (!at || Number.isNaN(at.getTime())) return day; return calendarDateInZone(at, timeZone ?? viewerTimeZone()); };