-
Notifications
You must be signed in to change notification settings - Fork 421
fix: Improve Date Parsing Robustness in NLP Fallback #1174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sarv-tech
wants to merge
3
commits into
Charushi06:main
Choose a base branch
from
sarv-tech:fix/nlp-date-parsing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| const test = require('node:test'); | ||
| const assert = require('node:assert/strict'); | ||
|
sarv-tech marked this conversation as resolved.
|
||
|
|
||
| test('isValidDate validation', async () => { | ||
| const { isValidDate } = await import('../js/utils/nlpDateExtractor.js'); | ||
| assert.equal(isValidDate(2023, 1, 28), true); // Feb 28 | ||
|
sarv-tech marked this conversation as resolved.
Outdated
|
||
| assert.equal(isValidDate(2023, 1, 29), false); // Feb 29 2023 (Not leap) | ||
| assert.equal(isValidDate(2024, 1, 29), true); // Feb 29 2024 (Leap) | ||
| assert.equal(isValidDate(2023, 3, 31), false); // Apr 31 | ||
| }); | ||
|
|
||
| test('Ambiguous Date Formats MM/DD/YYYY vs DD/MM/YYYY', async () => { | ||
| const { extractDate } = await import('../js/utils/nlpDateExtractor.js'); | ||
| const now = new Date(2023, 0, 1); | ||
|
|
||
| // Default MM/DD/YYYY | ||
| const res1 = extractDate("The deadline is 03/04/2023", now); | ||
| // Expect March 4, 2023 | ||
| assert.equal(new Date(res1).toISOString().startsWith('2023-03-04'), true); | ||
|
|
||
| // Fallback to DD/MM/YYYY when XX > 12 | ||
| const res2 = extractDate("The deadline is 15/04/2023", now); | ||
| // Expect April 15, 2023 | ||
| assert.equal(new Date(res2).toISOString().startsWith('2023-04-15'), true); | ||
| }); | ||
|
|
||
| test('Natural Language Phrases', async () => { | ||
| const { extractDate } = await import('../js/utils/nlpDateExtractor.js'); | ||
| const now = new Date(2023, 5, 10); // June 10, 2023 | ||
|
|
||
| // Mid-month | ||
| const midJan = extractDate("Submit by mid-January", now); | ||
| assert.equal(new Date(midJan).toISOString().startsWith('2024-01-15'), true); // Next year Jan | ||
|
|
||
| const midJune = extractDate("Submit by mid-June", now); | ||
| assert.equal(new Date(midJune).toISOString().startsWith('2023-06-15'), true); | ||
|
|
||
| // Beginning of next month | ||
| const beginningNext = extractDate("due beginning of next month", now); | ||
| assert.equal(new Date(beginningNext).toISOString().startsWith('2023-07-01'), true); | ||
|
|
||
| // First Monday of next month | ||
| const firstMonNext = extractDate("due first Monday of next month", now); | ||
| // Next month is July 2023. July 1, 2023 is Saturday (day 6). | ||
| // First Monday should be July 3, 2023. | ||
| assert.equal(new Date(firstMonNext).toISOString().startsWith('2023-07-03'), true); | ||
| }); | ||
|
|
||
| test('Graceful fallback for invalid parsed calendar dates', async () => { | ||
| const { extractDate } = await import('../js/utils/nlpDateExtractor.js'); | ||
| const now = new Date(2023, 0, 1); | ||
|
|
||
| // February 30th is invalid, should return null (so fallback handles it in caller) | ||
| const invalidDate = extractDate("due on Feb 30", now); | ||
| assert.equal(invalidDate, null); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.