Root Cause
The AI model (Gemini) was not provided with the current date context in the system instruction, making it impossible to accurately calculate relative dates like "next Friday", "tomorrow", "next month", etc.
Solution
Modified
aiProcessor.js
to include the current date and time at the beginning of every prompt sent to the AI.
Changes Made
Modified
aiProcessor.js
Added current date context to the prompt construction:
- const finalPromptInput = `${SYSTEM_INSTRUCTION_TEXT}\n\n--- USER REQUEST ---\n${userMessage}`;
+ // Include current date for accurate relative date parsing
+ const currentDateTime = new Date().toISOString();
+ const finalPromptInput = `CURRENT DATE AND TIME: ${currentDateTime}\n\n${SYSTEM_INSTRUCTION_TEXT}\n\n--- USER REQUEST ---\n${userMessage}`;
How It Works
Before sending the user's request to the AI, we now prepend the current date and time in ISO format (e.g., 2025-11-27T01:14:18.000Z)
The AI can now use this context to accurately interpret relative date expressions
The date parsing logic in
parseRawDate()
continues to work as before for absolute dates
Next Steps for Testing
To verify this fix works correctly:
Restart your application if it's currently running
Navigate to http://localhost:3000/search
Enter the prompt: "need flight from dubai to kuwait next friday"
Verify the returned DepartureDate matches the correct upcoming Friday
Expected Result
The departure date should now be November 28, 2025 (or the next Friday from the current date), not November 3, 2026.
Additional Notes
This fix applies to all relative date expressions: "tomorrow", "next week", "next month", etc.
The AI will receive the current date in ISO format for maximum compatibility
No changes were needed to the schema or date parsing logic