1
0

fix(natural language parser): parts of week days in other words

This commit is contained in:
kolaente
2021-09-26 15:00:11 +02:00
parent 403d77ce14
commit 4b64e27d2b
2 changed files with 35 additions and 2 deletions

View File

@ -222,7 +222,7 @@ export const getDateFromTextIn = (text: string, now: Date = new Date()) => {
}
const getDateFromWeekday = (text: string): dateFoundResult => {
const matcher: RegExp = / (next )?(monday|mon|tuesday|tue|wednesday|wed|thursday|thu|friday|fri|saturday|sat|sunday|sun)/ig
const matcher: RegExp = / (next )?(monday|mon|tuesday|tue|wednesday|wed|thursday|thu|friday|fri|saturday|sat|sunday|sun)($| )/ig
const results: string[] | null = matcher.exec(text)
if (results === null) {
return {
@ -274,8 +274,15 @@ const getDateFromWeekday = (text: string): dateFoundResult => {
const distance: number = (day + 7 - currentDay) % 7
date.setDate(date.getDate() + distance)
// This a space at the end of the found text to not break parsing suffix strings like "at 14:00" in cases where the
// matched string comes with a space at the end (last part of the regex).
let foundText = results[0]
if (foundText.endsWith(' ')) {
foundText = foundText.substr(0, foundText.length - 1)
}
return {
foundText: results[0],
foundText: foundText,
date: date,
}
}