From 8dfb34c863dce9f908038f0ac3667eb7b8a284ea Mon Sep 17 00:00:00 2001 From: Harry Martland Date: Tue, 26 Nov 2024 10:46:09 +0000 Subject: [PATCH] feat: add tonight as a quick add date option (#2866) Reviewed-on: https://kolaente.dev/vikunja/vikunja/pulls/2866 Reviewed-by: konrad Co-authored-by: Harry Martland Co-committed-by: Harry Martland --- .../src/components/tasks/partials/QuickAddMagic.vue | 1 + frontend/src/helpers/time/parseDate.ts | 5 +++++ frontend/src/modules/parseTaskText.test.ts | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/tasks/partials/QuickAddMagic.vue b/frontend/src/components/tasks/partials/QuickAddMagic.vue index 41cd2f9f2..880f05c48 100644 --- a/frontend/src/components/tasks/partials/QuickAddMagic.vue +++ b/frontend/src/components/tasks/partials/QuickAddMagic.vue @@ -62,6 +62,7 @@
  • Today
  • +
  • Tonight
  • Tomorrow
  • Next monday
  • This weekend
  • diff --git a/frontend/src/helpers/time/parseDate.ts b/frontend/src/helpers/time/parseDate.ts index fb074ae38..cd27c074d 100644 --- a/frontend/src/helpers/time/parseDate.ts +++ b/frontend/src/helpers/time/parseDate.ts @@ -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') } diff --git a/frontend/src/modules/parseTaskText.test.ts b/frontend/src/modules/parseTaskText.test.ts index 3855c7329..68baf8680 100644 --- a/frontend/src/modules/parseTaskText.test.ts +++ b/frontend/src/modules/parseTaskText.test.ts @@ -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}`)