Fix date parsing parsing words with weekdays in them
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kolaente 2021-07-25 12:37:38 +02:00
parent eac7c5d999
commit aff34e5a62
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 15 additions and 4 deletions

View File

@ -222,7 +222,7 @@ export const getDateFromTextIn = (text: string, now: Date = new Date()) => {
} }
const getDateFromWeekday = (text: string): dateFoundResult => { 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) const results: string[] | null = matcher.exec(text)
if (results === null) { if (results === null) {
return { return {
@ -235,7 +235,7 @@ const getDateFromWeekday = (text: string): dateFoundResult => {
const currentDay: number = date.getDay() const currentDay: number = date.getDay()
let day: number = 0 let day: number = 0
switch (results[0]) { switch (results[1]) {
case 'mon': case 'mon':
case 'monday': case 'monday':
day = 1 day = 1
@ -275,7 +275,7 @@ const getDateFromWeekday = (text: string): dateFoundResult => {
date.setDate(date.getDate() + distance) date.setDate(date.getDate() + distance)
return { return {
foundText: results[0], foundText: results[1],
date: date, date: date,
} }
} }

View File

@ -194,6 +194,18 @@ describe('Parse Task Text', () => {
expect(result.text).toBe('Lorem Ipsum') expect(result.text).toBe('Lorem Ipsum')
expect(result.date.getDate()).toBe(date.getDate() + 1) 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', () => { describe('Parse date from text', () => {
const now = new Date() const now = new Date()
@ -270,7 +282,6 @@ describe('Parse Task Text', () => {
}) })
} }
}) })
}) })
describe('Labels', () => { describe('Labels', () => {