feat: add support for more cases
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
kolaente 2021-12-04 21:07:21 +01:00
parent 903d02be61
commit fbeeff6e59
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 55 additions and 18 deletions

View File

@ -529,6 +529,15 @@ describe('Parse Task Text', () => {
'every year': {type: 'years', amount: 1}, 'every year': {type: 'years', amount: 1},
'every 1 year': {type: 'years', amount: 1}, 'every 1 year': {type: 'years', amount: 1},
'every 4 years': {type: 'years', amount: 4}, 'every 4 years': {type: 'years', amount: 4},
'anually': {type: 'years', amount: 1},
'bianually': {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},
} }
for (const c in cases) { for (const c in cases) {

View File

@ -157,7 +157,7 @@ const getPriority = (text: string, prefix: string): number | null => {
} }
const getRepeats = (text: string): repeatParsedResult => { const getRepeats = (text: string): repeatParsedResult => {
const regex = /((every|each) ([0-9]+ )?(hours?|days?|weeks?|months?|years?))/ig const regex = /((every|each) ([0-9]+ )?(hours?|days?|weeks?|months?|years?))|anually|bianually|semiannually|biennially|daily|hourly|monthly|weekly|yearly/ig
const results = regex.exec(text) const results = regex.exec(text)
if (results === null) { if (results === null) {
return { return {
@ -166,9 +166,36 @@ const getRepeats = (text: string): repeatParsedResult => {
} }
} }
const amount = results[3] ? parseInt(results[3]) : 1 let amount = results[3] ? parseInt(results[3]) : 1
let type: RepeatType = RepeatType.Hours let type: RepeatType = RepeatType.Hours
switch (results[0]) {
case 'biennially':
type = RepeatType.Years
amount = 2
break
case 'bianually':
case 'semiannually':
type = RepeatType.Months
amount = 6
break
case 'yearly':
case 'anually':
type = RepeatType.Years
break
case 'daily':
type = RepeatType.Days
break
case 'hourly':
type = RepeatType.Hours
break
case 'monthly':
type = RepeatType.Months
break
case 'weekly':
type = RepeatType.Weeks
break
default:
switch (results[4]) { switch (results[4]) {
case 'hour': case 'hour':
case 'hours': case 'hours':
@ -191,6 +218,7 @@ const getRepeats = (text: string): repeatParsedResult => {
type = RepeatType.Years type = RepeatType.Years
break break
} }
}
return { return {
textWithoutMatched: text.replace(results[0], ''), textWithoutMatched: text.replace(results[0], ''),