Project

General

Profile

Actions

Improvement #30520

open

Improvement #29635: Code Review, Upgrade and changes in Prompt of Email Boat

Departure Date Parsing for Relative Dates

Added by Sachin Suresh 5 months ago. Updated 5 months ago.

Status:
Fixed not Tested
Priority:
Normal
Assignee:
Target version:
-
Start date:
11/27/2025
Due date:
11/27/2025 (about 5 months late)
% Done:

100%

Estimated time:
0:30 h
Spent time:
remarks:
DB Changes:
Keys & Permissions:
Areas Affected:
Files Changed:

Description

When users entered natural language flight requests with relative dates (e.g., "next Friday"), the AI was returning incorrect dates far in the future (November 3, 2026 instead of the correct upcoming Friday).

Actions #1

Updated by Sachin Suresh 5 months ago

  • Status changed from Assigned to In Progress
Actions #2

Updated by Sachin Suresh 5 months ago

  • Status changed from In Progress to Fixed not Tested
  • % Done changed from 0 to 100

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

Actions #3

Updated by Sachin Suresh 5 months ago

Issue fixed AI Agent

Actions

Also available in: Atom PDF