Safely converts any timestamp format to a Date object
export const parseTimestamp = (timestamp: string): Date | null => { if (!timestamp) return null; try { if (!isNaN(Number(timestamp))) { return new Date(Number(timestamp)); } else { return new Date(timestamp); } } catch (error) { console.error("Error parsing timestamp:", error); return null; }}; Copy
export const parseTimestamp = (timestamp: string): Date | null => { if (!timestamp) return null; try { if (!isNaN(Number(timestamp))) { return new Date(Number(timestamp)); } else { return new Date(timestamp); } } catch (error) { console.error("Error parsing timestamp:", error); return null; }};
Timestamp string (ISO or numeric)
Date object or null if invalid
Safely converts any timestamp format to a Date object
Source