// Helper to combine Date and Time strings into a Date object
const combineDateAndTime = (dateStr, timeStr) => {
    if (!dateStr) return null;
    // Assuming dateStr is "YYYY-MM-DD" or similar, and timeStr is "HH:MM" or "HH:MM AM/PM"
    // For simplicity, let's assume the frontend sends a valid date string or ISO string.
    // If timeStr is provided, we might need to parse it. 
    // Ideally, frontend sends full ISO strings. 
    // But based on image "20 Aug 25" and "10:00 AM", we might get separate fields.

    // Let's try to construct it. 
    // If dateStr is already a full date object/string, use it.
    const date = new Date(dateStr);
    if (isNaN(date.getTime())) return null;

    if (timeStr) {
        // Simple parser for "10:00 AM" or "10:00"
        const [time, modifier] = timeStr.split(' ');
        let [hours, minutes] = time.split(':');

        if (hours === '12') {
            hours = '00';
        }

        if (modifier === 'PM') {
            hours = parseInt(hours, 10) + 12;
        } else if (modifier === 'AM' && hours === '12') { // 12 AM is 00
            hours = '00';
        }

        date.setHours(hours || 0);
        date.setMinutes(minutes || 0);
    }
    return date;
};

module.exports = combineDateAndTime;