fix(quick add magic): repeating intervals in words
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Resolves #3676
This commit is contained in:
parent
25b110ce48
commit
d7ce8dd320
@ -719,15 +719,6 @@ describe('Parse Task Text', () => {
|
||||
'every year': {type: 'years', amount: 1},
|
||||
'every 1 year': {type: 'years', amount: 1},
|
||||
'every 4 years': {type: 'years', amount: 4},
|
||||
'annually': {type: 'years', amount: 1},
|
||||
'biannually': {type: 'months', amount: 6},
|
||||
'semiannually': {type: 'months', amount: 6},
|
||||
'biennially': {type: 'years', amount: 2},
|
||||
'daily': {type: 'days', amount: 1},
|
||||
'hourly': {type: 'hours', amount: 1},
|
||||
'monthly': {type: 'months', amount: 1},
|
||||
'weekly': {type: 'weeks', amount: 1},
|
||||
'yearly': {type: 'years', amount: 1},
|
||||
'every one hour': {type: 'hours', amount: 1}, // maybe unnesecary but better to include it for completeness sake
|
||||
'every two hours': {type: 'hours', amount: 2},
|
||||
'every three hours': {type: 'hours', amount: 3},
|
||||
@ -738,6 +729,15 @@ describe('Parse Task Text', () => {
|
||||
'every eight hours': {type: 'hours', amount: 8},
|
||||
'every nine hours': {type: 'hours', amount: 9},
|
||||
'every ten hours': {type: 'hours', amount: 10},
|
||||
'annually': {type: 'years', amount: 1},
|
||||
'biannually': {type: 'months', amount: 6},
|
||||
'semiannually': {type: 'months', amount: 6},
|
||||
'biennially': {type: 'years', amount: 2},
|
||||
'daily': {type: 'days', amount: 1},
|
||||
'hourly': {type: 'hours', amount: 1},
|
||||
'monthly': {type: 'months', amount: 1},
|
||||
'weekly': {type: 'weeks', amount: 1},
|
||||
'yearly': {type: 'years', amount: 1},
|
||||
} as Record<string, IRepeatAfter>
|
||||
|
||||
for (const c in cases) {
|
||||
@ -749,5 +749,26 @@ describe('Parse Task Text', () => {
|
||||
expect(result?.repeats?.amount).toBe(cases[c].amount)
|
||||
})
|
||||
}
|
||||
|
||||
const wordCases = [
|
||||
'annually',
|
||||
'biannually',
|
||||
'semiannually',
|
||||
'biennially',
|
||||
'daily',
|
||||
'hourly',
|
||||
'monthly',
|
||||
'weekly',
|
||||
'yearly',
|
||||
]
|
||||
|
||||
wordCases.forEach(c => {
|
||||
it(`should ignore recurring periods if they are part of a word ${c}`, () => {
|
||||
const result = parseTaskText(`Lorem Ipsum word${c}notword`)
|
||||
|
||||
expect(result.text).toBe(`Lorem Ipsum word${c}notword`)
|
||||
expect(result?.repeats).toBeNull()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -165,7 +165,7 @@ const getPriority = (text: string, prefix: string): number | null => {
|
||||
}
|
||||
|
||||
const getRepeats = (text: string): repeatParsedResult => {
|
||||
const regex = /((every|each) (([0-9]+|one|two|three|four|five|six|seven|eight|nine|ten) )?(hours?|days?|weeks?|months?|years?))|annually|biannually|semiannually|biennially|daily|hourly|monthly|weekly|yearly/ig
|
||||
const regex = /(^| )(((every|each) (([0-9]+|one|two|three|four|five|six|seven|eight|nine|ten) )?(hours?|days?|weeks?|months?|years?))|(annually|biannually|semiannually|biennially|daily|hourly|monthly|weekly|yearly))($| )/ig
|
||||
const results = regex.exec(text)
|
||||
if (results === null) {
|
||||
return {
|
||||
@ -175,7 +175,7 @@ const getRepeats = (text: string): repeatParsedResult => {
|
||||
}
|
||||
|
||||
let amount = 1
|
||||
switch (results[3] ? results[3].trim() : undefined) {
|
||||
switch (results[5] ? results[5].trim() : undefined) {
|
||||
case 'one':
|
||||
amount = 1
|
||||
break
|
||||
@ -207,11 +207,11 @@ const getRepeats = (text: string): repeatParsedResult => {
|
||||
amount = 10
|
||||
break
|
||||
default:
|
||||
amount = results[3] ? parseInt(results[3]) : 1
|
||||
amount = results[5] ? parseInt(results[5]) : 1
|
||||
}
|
||||
let type: IRepeatType = REPEAT_TYPES.Hours
|
||||
|
||||
switch (results[0]) {
|
||||
switch (results[2]) {
|
||||
case 'biennially':
|
||||
type = REPEAT_TYPES.Years
|
||||
amount = 2
|
||||
@ -238,7 +238,7 @@ const getRepeats = (text: string): repeatParsedResult => {
|
||||
type = REPEAT_TYPES.Weeks
|
||||
break
|
||||
default:
|
||||
switch (results[5]) {
|
||||
switch (results[7]) {
|
||||
case 'hour':
|
||||
case 'hours':
|
||||
type = REPEAT_TYPES.Hours
|
||||
|
Reference in New Issue
Block a user