fix(quick add magic): assume today when no date was specified with time
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
5af8b54618
commit
92cdf5fe9c
@ -79,6 +79,12 @@ export const parseDate = (text: string, now: Date = new Date()): dateParseResult
|
||||
parsed = getDateFromText(text, now)
|
||||
|
||||
if (parsed.date === null) {
|
||||
const time = addTimeToDate(text, new Date(now), parsed.foundText)
|
||||
|
||||
if (time.date !== null && +now !== +time.date) {
|
||||
return time
|
||||
}
|
||||
|
||||
return {
|
||||
newText: replaceAll(text, parsed.foundText, ''),
|
||||
date: parsed.date,
|
||||
@ -122,7 +128,7 @@ const addTimeToDate = (text: string, date: Date, previousMatch: string | null):
|
||||
const replace = results !== null ? results[0] : previousMatch
|
||||
return {
|
||||
newText: replaceAll(text, replace, '').trim(),
|
||||
date: date,
|
||||
date,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -804,6 +804,17 @@ describe('Parse Task Text', () => {
|
||||
expect(result?.repeats?.type).toBe(cases[c].type)
|
||||
expect(result?.repeats?.amount).toBe(cases[c].amount)
|
||||
})
|
||||
|
||||
it(`should parse ${c} as recurring date every ${cases[c].amount} ${cases[c].type} at 11:42`, () => {
|
||||
const result = parseTaskText(`Lorem Ipsum ${c} at 11:42`)
|
||||
|
||||
expect(result.text).toBe('Lorem Ipsum')
|
||||
expect(result?.repeats?.type).toBe(cases[c].type)
|
||||
expect(result?.repeats?.amount).toBe(cases[c].amount)
|
||||
const now = new Date()
|
||||
expect(`${result?.date?.getFullYear()}-${result?.date?.getMonth()}-${result?.date?.getDate()}`).toBe(`${now.getFullYear()}-${now.getMonth()}-${now.getDate()}`)
|
||||
expect(`${result?.date?.getHours()}:${result?.date?.getMinutes()}`).toBe('11:42')
|
||||
})
|
||||
}
|
||||
|
||||
const wordCases = [
|
||||
|
@ -261,9 +261,14 @@ const getRepeats = (text: string): repeatParsedResult => {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let matchedText = results[0]
|
||||
if(matchedText.endsWith(' ')) {
|
||||
matchedText = matchedText.substring(0, matchedText.length - 1)
|
||||
}
|
||||
|
||||
return {
|
||||
textWithoutMatched: text.replace(results[0], ''),
|
||||
textWithoutMatched: text.replace(matchedText, ''),
|
||||
repeats: {
|
||||
amount,
|
||||
type,
|
||||
|
Loading…
x
Reference in New Issue
Block a user