-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Date Parser Any Parsing Two-Digit Number as Year #4242
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
Fix Date Parser Any Parsing Two-Digit Number as Year #4242
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/app/features/tasks/short-syntax.ts:321
- [nitpick] The hacky check for a time estimate appended to the date might not handle all edge cases. A clearer separation of date and time estimate parsing would improve robustness.
if (inputDate.match(/ [0-9]{1,}m/g)) {
if (matched) { | ||
if (matched[matched.length - 1]) { | ||
const twoDigits = matched[matched.length - 1]; | ||
result.text = text.replace(twoDigits, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing the two-digit year indiscriminately may remove matching digits elsewhere in the string. Consider targeting the exact location of the match or using a more precise replacement strategy.
result.text = text.replace(twoDigits, ''); | |
const startIndex = matched.index + matched[0].lastIndexOf(twoDigits); | |
const endIndex = startIndex + twoDigits.length; | |
result.text = text.slice(0, startIndex) + text.slice(endIndex); |
Copilot uses AI. Check for mistakes.
Hey @bytrangle ! Thank you for this PR! Could you maybe also add some unit tests for this? Tbh I am a bit hesitant to merge this, since I am afraid of this causing new unintended problems with the new regex. Chrono node is well tested and used by many projects so we have to make sure to replace it with something reliable. Some unit tests for the different cases would give me more confidence :) |
Will do. I'm also scared of implementing this change because it may lead to some edge cases that I can't possibly imagine. No date parsing tool is better than Chrono in the Javascript ecosystem, but I feel like it has become too relaxing over time :) |
@bytrangle I hope you don't mind I'm testing this @CodiumAI-Agent /review |
PR Reviewer Guide 🔍(Review updated until commit b3ab685)Here are some key observations to aid the review process:
|
Thank you very much! Seems to work well as far as I can tell. I will merge this. If we encounter additional issues we can fix them in a separate PR. |
Persistent review updated to latest commit b3ab685 |
Description
When user creates a new task which includes short syntax for date, then following by a two-digit number, the number will be interpreted as year.
For example: "Task
@
14/4 90m". Implication: User schedules the task for 14/4 going forward and estimates the task as taking 90 minutes. Two problems:Changes I've made:
DD/MM YY
. The regex pattern is more complicated than that, because there are so many ways a user can write date informally. It doesn't take into account syntax like "August 8 90m".parseScheduledDate
is changed so that the word "m" won't be a part of the final task title.Issues Resolved
Potentially fixes #4194
Check List