feat: add tonight as a quick add date option (#2866)

Reviewed-on: https://kolaente.dev/vikunja/vikunja/pulls/2866
Reviewed-by: konrad <k@knt.li>
Co-authored-by: Harry Martland <HarryEMartland@gmail.com>
Co-committed-by: Harry Martland <HarryEMartland@gmail.com>
This commit is contained in:
Harry Martland
2024-11-26 10:46:09 +00:00
committed by konrad
parent ed071e504e
commit 8dfb34c863
3 changed files with 17 additions and 1 deletions

View File

@@ -62,6 +62,7 @@
<ul>
<!-- Not localized because these only work in english -->
<li>Today</li>
<li>Tonight</li>
<li>Tomorrow</li>
<li>Next monday</li>
<li>This weekend</li>

View File

@@ -22,6 +22,11 @@ export const parseDate = (text: string, now: Date = new Date()): dateParseResult
if (matchesDateExpr(text, 'today')) {
return addTimeToDate(text, getDateFromInterval(calculateDayInterval('today')), 'today')
}
if (matchesDateExpr(text, 'tonight')) {
const taskDate = getDateFromInterval(calculateDayInterval('today'))
taskDate.setHours(21)
return addTimeToDate(text, taskDate, 'tonight')
}
if (matchesDateExpr(text, 'tomorrow')) {
return addTimeToDate(text, getDateFromInterval(calculateDayInterval('tomorrow')), 'tomorrow')
}

View File

@@ -75,6 +75,16 @@ describe('Parse Task Text', () => {
expect(result?.date?.getMonth()).toBe(now.getMonth())
expect(result?.date?.getDate()).toBe(now.getDate())
})
it('should recognize tonight', () => {
const result = parseTaskText('Lorem Ipsum tonight')
expect(result.text).toBe('Lorem Ipsum')
const now = new Date()
expect(result?.date?.getFullYear()).toBe(now.getFullYear())
expect(result?.date?.getMonth()).toBe(now.getMonth())
expect(result?.date?.getDate()).toBe(now.getDate())
expect(result?.date?.getHours()).toBe(21)
})
describe('should recognize today with a time', () => {
const cases = {
'at 15:00': '15:0',
@@ -87,7 +97,7 @@ describe('Parse Task Text', () => {
'at 3:12 am': '3:12',
'at 3:12 pm': '15:12',
} as const
for (const c in cases) {
it(`should recognize today with a time ${c}`, () => {
const result = parseTaskText(`Lorem Ipsum today ${c}`)