Fix date parsing parsing words with weekdays in them
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
eac7c5d999
commit
aff34e5a62
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
Reference in New Issue