Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 5x 5x 5x | /**
* Format a SQL DATE string (no time component, e.g. "2026-05-07") for
* display in the user's locale.
*
* Why this exists: `new Date("2026-05-07")` parses as `00:00 UTC`. When
* the browser's local timezone is west of UTC the formatted string then
* shows the *previous* day. Appending a local-midnight time component
* forces the parser to interpret the date as local, matching what the
* backend stored (FSC-82).
*
* If the input already includes a time component, it's passed through
* to the Date constructor unchanged.
*/
export function formatDateOnly(
dateString: string,
options: Intl.DateTimeFormatOptions = {year: 'numeric', month: 'long', day: 'numeric'}
): string {
const hasTime = dateString.includes('T') || dateString.includes(' ');
const parsed = hasTime
? new Date(dateString)
: new Date(`${dateString}T00:00:00`);
return parsed.toLocaleDateString('en-US', options);
}
|