export const formatToDateTimeString = (dateString: string): string => { const date = new Date(dateString); const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, "0"); // months are 0-indexed const day = String(date.getDate()).padStart(2, "0"); const hours = String(date.getHours()).padStart(2, "0"); const minutes = String(date.getMinutes()).padStart(2, "0"); const seconds = String(date.getSeconds()).padStart(2, "0"); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; }; export const getDefaultDateRange = () => { const endDate = new Date(); const startDate = new Date(); startDate.setHours(startDate.getHours() - 24); return { dateStart: startDate.toISOString(), dateEnd: endDate.toISOString(), }; }; /** * Normalize date range for API calls * - Start date is set to beginning of day (00:00:00.000) * - End date is set to end of day (23:59:59.999) * This ensures same-day selections include the entire day */ export const normalizeDateRangeForAPI = ( startDate: Date, endDate: Date ): { dateStart: string; dateEnd: string } => { // Clone dates to avoid mutating originals const normalizedStart = new Date(startDate); const normalizedEnd = new Date(endDate); // Set start date to beginning of day normalizedStart.setHours(0, 0, 0, 0); // Set end date to end of day normalizedEnd.setHours(23, 59, 59, 999); return { dateStart: normalizedStart.toISOString(), dateEnd: normalizedEnd.toISOString(), }; };