Enhance due date parsing by validating word boundaries to prevent partial matches

This commit is contained in:
Mo Tarbin
2026-05-25 12:46:18 -04:00
parent b54f4a846c
commit d10727b87d

View File

@@ -672,7 +672,29 @@ export const parseDueDate = (inputSentence, chrono) => {
} }
} }
const dueDateMatch = parsedDueDate[0] let dueDateMatch = parsedDueDate[0]
// Validate word boundaries for the matched date text
// This prevents matching partial words like "wed" in "wedding", fri in "friend", etc.
const matchStart = dueDateMatch.index
const matchEnd = matchStart + dueDateMatch.text.length
const charBefore = matchStart > 0 ? inputSentence[matchStart - 1] : ' '
const charAfter =
matchEnd < inputSentence.length ? inputSentence[matchEnd] : ' '
// Check if the match is part of a larger word
// If alphanumeric characters exist before/after, it's not a word boundary
const isValidWordBoundary =
!/[a-zA-Z0-9]/.test(charBefore) && !/[a-zA-Z0-9]/.test(charAfter)
if (!isValidWordBoundary) {
return {
result: null,
highlight: [],
cleanedSentence: inputSentence,
}
}
const dueDateText = dueDateMatch.text const dueDateText = dueDateMatch.text
const dueDateStartIndex = dueDateMatch.index const dueDateStartIndex = dueDateMatch.index
const dueDateEndIndex = dueDateStartIndex + dueDateText.length const dueDateEndIndex = dueDateStartIndex + dueDateText.length