date-format.ts855 BView on GitHub /**
* Pure date formatting helpers, split out of ./time.
*
* ./time imports chrono-node and fuse.js at module scope for natural-language date parsing. The
* crm/utils barrel is reachable from `userTasksSlice`, which modules/store/index.ts registers
* eagerly, so importing a single pure helper from ./time put both NLP libraries on the critical
* path of every route.
*
* Keep this module dependency-free.
*
* See docs/design/frontend-load-performance.md §3 F5.
*/
export function toISODateString(date: Date | string | null | undefined): string | undefined {
if (!date) return undefined;
// If already a string (from cache), extract date portion
if (typeof date === 'string') {
return date.split('T')[0];
}
// If it's a Date object (from fresh tRPC response), convert to ISO string
return date.toISOString().split('T')[0];
}