fix: move from/to parsing to the very top #8389
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to the documentation, there's an option to use the syntax "from ... to ..." for dateRange, which uses the Chrono library under the hood.
My intention is to get a relative dateRange for the entire week a week ago. The prompt I use is
from (14 days before this week) to (7 days before this week)
. If I put the prompt into Chrono standalone, it works perfectly and returns the dates I expect. However, Cube processes it differently — it only returns the date range for "last week" and ignores the rest of the prompt.I investigated the source code and realised this issue occurs because of the order of conditions in dateParser.js. If a prompt contains "this week", "this month", "this day", etc., only this part will be handled, and the rest will be ignored. My proposal in this PR is to move the "from / to" condition to the very top, ensuring that 'from / to' will also be handled if they contain "this week", "this month", "this day", etc.