From aff34e5a62f10c3d5c5a26c29502bbb83067fe17 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 25 Jul 2021 12:37:38 +0200 Subject: [PATCH] Fix date parsing parsing words with weekdays in them --- src/helpers/time/parseDate.ts | 6 +++--- src/modules/parseTaskText.test.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/helpers/time/parseDate.ts b/src/helpers/time/parseDate.ts index e7a307091..762f9f72b 100644 --- a/src/helpers/time/parseDate.ts +++ b/src/helpers/time/parseDate.ts @@ -222,7 +222,7 @@ export const getDateFromTextIn = (text: string, now: Date = new Date()) => { } const getDateFromWeekday = (text: string): dateFoundResult => { - const matcher: RegExp = /(mon|monday|tue|tuesday|wed|wednesday|thu|thursday|fri|friday|sat|saturday|sun|sunday)/ig + const matcher: RegExp = / (mon|monday|tue|tuesday|wed|wednesday|thu|thursday|fri|friday|sat|saturday|sun|sunday)/ig const results: string[] | null = matcher.exec(text) if (results === null) { return { @@ -235,7 +235,7 @@ const getDateFromWeekday = (text: string): dateFoundResult => { const currentDay: number = date.getDay() let day: number = 0 - switch (results[0]) { + switch (results[1]) { case 'mon': case 'monday': day = 1 @@ -275,7 +275,7 @@ const getDateFromWeekday = (text: string): dateFoundResult => { date.setDate(date.getDate() + distance) return { - foundText: results[0], + foundText: results[1], date: date, } } diff --git a/src/modules/parseTaskText.test.js b/src/modules/parseTaskText.test.js index 652941e83..a3710df33 100644 --- a/src/modules/parseTaskText.test.js +++ b/src/modules/parseTaskText.test.js @@ -194,6 +194,18 @@ describe('Parse Task Text', () => { expect(result.text).toBe('Lorem Ipsum') expect(result.date.getDate()).toBe(date.getDate() + 1) }) + it('should only recognize weekdays with a space before or after them 1', () => { + const result = parseTaskText('Lorem Ipsum renewed') + + expect(result.text).toBe('Lorem Ipsum renewed') + expect(result.date).toBeNull() + }) + it('should only recognize weekdays with a space before or after them 2', () => { + const result = parseTaskText('Lorem Ipsum github') + + expect(result.text).toBe('Lorem Ipsum github') + expect(result.date).toBeNull() + }) describe('Parse date from text', () => { const now = new Date() @@ -270,7 +282,6 @@ describe('Parse Task Text', () => { }) } }) - }) describe('Labels', () => {