Skip to content

fix: Improve Date Parsing Robustness in NLP Fallback#1174

Open
sarv-tech wants to merge 3 commits into
Charushi06:mainfrom
sarv-tech:fix/nlp-date-parsing
Open

fix: Improve Date Parsing Robustness in NLP Fallback#1174
sarv-tech wants to merge 3 commits into
Charushi06:mainfrom
sarv-tech:fix/nlp-date-parsing

Conversation

@sarv-tech

Copy link
Copy Markdown

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 returning null.

  • Enhanced nlpExtractDate() to support:

    • mid-[month] (e.g., mid-January)
    • beginning of next month
    • first [weekday] of next month
  • Improved ambiguous numeric date handling:

    • Default interpretation: MM/DD/YYYY
    • Fallback to DD/MM/YYYY when 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)

  • Mirrored backend parsing enhancements to maintain consistent behavior.
  • Added robust validation during year resolution and date extraction.
  • Added support for the same natural language date expressions handled by the backend.

Testing

Added a new test suite:

  • tests/nlpDate.test.js

Coverage includes:

  • Ambiguous date formats

  • Missing year scenarios

  • Invalid calendar dates

  • Leap year validation

  • Natural language expressions:

    • mid-January
    • beginning of next month
    • first Monday of next month
  • Graceful fallback behavior

  • Regression coverage for existing functionality

Verification

Automated Testing

  • Ran existing test suite.
  • Ran NLP date parsing tests.
  • Confirmed all tests pass successfully.
  • Verified no regressions in existing functionality.

Manual Testing

Verified expected behavior through API testing using sample NLP date inputs, including:

  • Ambiguous date formats
  • Natural language date expressions
  • Invalid dates
  • Fallback scenarios

Notes

  • Frontend and backend implementations remain synchronized.
  • No unrelated functionality was modified.
  • Future enhancement opportunity: locale-aware date parsing for fully ambiguous date formats.

Checklist

  • Issue scope fully implemented
  • Tests added/updated
  • Existing functionality preserved
  • No unrelated changes included
  • Ready for maintainer review

Acceptance Criteria

  • Support ambiguous date formats with a documented interpretation strategy.

    • Implemented MM/DD/YYYY as the default interpretation.
    • Added DD/MM/YYYY fallback when the first value is greater than 12 and the second value is 12 or less.
    • Documented behavior for fully ambiguous cases.
  • Add validation for invalid calendar dates.

    • Added isValidDate() validation.
    • Rejects impossible dates such as February 30 and April 31.
  • Improve handling of natural language date expressions.

    • Added support for:

      • mid-[month]
      • beginning of next month
      • first [weekday] of next month
  • Add comprehensive unit tests covering edge cases.

    • Added tests for ambiguous dates.
    • Added tests for invalid calendar dates.
    • Added tests for missing year scenarios.
    • Added tests for natural language date expressions.
    • Added regression coverage for existing behavior.
  • Maintain backward compatibility with existing supported formats.

    • Existing supported date extraction formats continue to function as before.
    • No breaking changes introduced.
  • Ensure graceful fallback for unsupported inputs.

    • Invalid or unsupported date expressions return null and correctly fall back through the existing NLP fallback flow.

Fixes #1173

Copilot AI review requested due to automatic review settings June 19, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 return null for invalid dates.
  • Extended parsing to handle mid-[month], beginning of next month, and first <weekday> of next month, plus improved ambiguous numeric date interpretation.
  • Added a new node:test suite 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.

Comment thread server.js Outdated
Comment thread server.js Outdated
Comment thread js/utils/nlpDateExtractor.js Outdated
Comment thread tests/nlpDate.test.js
Comment thread tests/nlpDate.test.js Outdated
sarv-tech and others added 2 commits June 20, 2026 01:59
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sarv-tech

Copy link
Copy Markdown
Author

hi @Charushi06 , i've create a PR for issue #1173 . pls review it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Improve Date Parsing Robustness in NLP Fallback (Backend)

2 participants