mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-11 17:48:44 -05:00
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:
@@ -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>
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
@@ -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}`)
|
||||
|
||||
Reference in New Issue
Block a user