feat: add support for passing in numbers as words
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kolaente 2021-12-07 20:36:35 +01:00
parent 88a115a6b0
commit 32062b3b82
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 47 additions and 3 deletions

View File

@ -538,6 +538,16 @@ describe('Parse Task Text', () => {
'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},
'every four hours': {type: 'hours', amount: 4},
'every five hours': {type: 'hours', amount: 5},
'every six hours': {type: 'hours', amount: 6},
'every seven hours': {type: 'hours', amount: 7},
'every eight hours': {type: 'hours', amount: 8},
'every nine hours': {type: 'hours', amount: 9},
'every ten hours': {type: 'hours', amount: 10},
}
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 regex = /((every|each) ([0-9]+ )?(hours?|days?|weeks?|months?|years?))|anually|bianually|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?))|anually|bianually|semiannually|biennially|daily|hourly|monthly|weekly|yearly/ig
const results = regex.exec(text)
if (results === null) {
return {
@ -166,7 +166,41 @@ const getRepeats = (text: string): repeatParsedResult => {
}
}
let amount = results[3] ? parseInt(results[3]) : 1
let amount = 1
switch (results[3] ? results[3].trim() : undefined) {
case 'one':
amount = 1
break
case 'two':
amount = 2
break
case 'three':
amount = 3
break
case 'four':
amount = 4
break
case 'five':
amount = 5
break
case 'six':
amount = 6
break
case 'seven':
amount = 7
break
case 'eight':
amount = 8
break
case 'nine':
amount = 9
break
case 'ten':
amount = 10
break
default:
amount = results[3] ? parseInt(results[3]) : 1
}
let type: RepeatType = RepeatType.Hours
switch (results[0]) {
@ -196,7 +230,7 @@ const getRepeats = (text: string): repeatParsedResult => {
type = RepeatType.Weeks
break
default:
switch (results[4]) {
switch (results[5]) {
case 'hour':
case 'hours':
type = RepeatType.Hours