fix: Improve Date Parsing Robustness in NLP Fallback#1174
Open
sarv-tech wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR strengthens the heuristic (non-AI) NLP date parsing used when external AI services are unavailable, aiming to make backend (server.js) and frontend (js/utils/nlpDateExtractor.js) behavior more robust and consistent, and adds unit tests for the client-side extractor.
Changes:
- Added calendar date validation (
isValidDate) and made year resolution returnnullfor invalid dates. - Extended parsing to handle
mid-[month],beginning of next month, andfirst <weekday> of next month, plus improved ambiguous numeric date interpretation. - Added a new
node:testsuite covering the frontend extractor.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
server.js |
Adds date validation and new NLP date phrases / ambiguous numeric date handling in the backend fallback parser. |
js/utils/nlpDateExtractor.js |
Mirrors the backend parsing enhancements in the client-side extractor. |
tests/nlpDate.test.js |
Adds unit tests for the frontend NLP date extractor behaviors. |
package-lock.json |
Updates Node engine range metadata in the lockfile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Author
|
hi @Charushi06 , i've create a PR for issue #1173 . pls review it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR improves the NLP fallback date extraction logic across both the backend and frontend implementations, making date parsing more reliable, predictable, and resilient when external AI services are unavailable.
Changes Made
Backend (
server.js)Added calendar date validation using
isValidDate(year, month, day).Updated
nlpResolveYear()to reject invalid dates by returningnull.Enhanced
nlpExtractDate()to support:mid-[month](e.g.,mid-January)beginning of next monthfirst [weekday] of next monthImproved ambiguous numeric date handling:
MM/DD/YYYYDD/MM/YYYYwhen the first value is greater than 12 and the second value is 12 or less.Ensured invalid parsing results gracefully fall back through existing fallback mechanisms.
Frontend (
js/utils/nlpDateExtractor.js)Testing
Added a new test suite:
tests/nlpDate.test.jsCoverage includes:
Ambiguous date formats
Missing year scenarios
Invalid calendar dates
Leap year validation
Natural language expressions:
mid-Januarybeginning of next monthfirst Monday of next monthGraceful fallback behavior
Regression coverage for existing functionality
Verification
Automated Testing
Manual Testing
Verified expected behavior through API testing using sample NLP date inputs, including:
Notes
Checklist
Acceptance Criteria
Support ambiguous date formats with a documented interpretation strategy.
Add validation for invalid calendar dates.
isValidDate()validation.Improve handling of natural language date expressions.
Added support for:
mid-[month]beginning of next monthfirst [weekday] of next monthAdd comprehensive unit tests covering edge cases.
Maintain backward compatibility with existing supported formats.
Ensure graceful fallback for unsupported inputs.
nulland correctly fall back through the existing NLP fallback flow.Fixes #1173