From 69367516d9d25ff3e59079b6f5c88576e40d862f Mon Sep 17 00:00:00 2001 From: Lars Lockefeer Date: Wed, 19 Jan 2022 21:20:39 +0100 Subject: [PATCH] Include someday/maybe tasks in daily notes in the someday/maybe list --- DemoVault/Daily Notes/2022-01-04.md | 4 +++- model/TodoParser.test.ts | 26 ++++++++++++++++++++++++++ model/TodoParser.ts | 5 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/DemoVault/Daily Notes/2022-01-04.md b/DemoVault/Daily Notes/2022-01-04.md index 90909cf..4f946df 100644 --- a/DemoVault/Daily Notes/2022-01-04.md +++ b/DemoVault/Daily Notes/2022-01-04.md @@ -1 +1,3 @@ -- [ ] Do something on this date \ No newline at end of file +- [ ] Do something on this date +- [ ] Do something in 2099 [due:: 2099-01-01] +- [ ] Do something, some day #someday \ No newline at end of file diff --git a/model/TodoParser.test.ts b/model/TodoParser.test.ts index a9ce49f..ae9e8c1 100644 --- a/model/TodoParser.test.ts +++ b/model/TodoParser.test.ts @@ -70,3 +70,29 @@ test('parsing a todo in a daily notes file', async () => { expect(todo.actionDate.month).toEqual(DateTime.now().month); expect(todo.actionDate.year).toEqual(DateTime.now().year); }); + +test('parsing a todo in a daily notes file with a due date', async () => { + const contents = `- [ ] This is something that needs doing #2022-04-01`; + const todos = await todoParser.parseTasks('/Daily Notes/today.md', contents); + const todo = todos[0]; + expect(todo.actionDate.day).toEqual(1); + expect(todo.actionDate.month).toEqual(4); + expect(todo.actionDate.year).toEqual(2022); +}); + +test('parsing a todo in a daily notes file tagged as someday/maybe', async () => { + const contents = `- [ ] This is something that needs doing #someday`; + const todos = await todoParser.parseTasks('/Daily Notes/today.md', contents); + const todo = todos[0]; + expect(todo.actionDate).toBeUndefined(); + expect(todo.isSomedayMaybeNote).toEqual(true); +}); + +test('parsing an outstanding todo with a specific action date and a someday/maybe tag', async () => { + const contents = `- [ ] This is something that needs doing #2021-02-16 #someday`; + const todos = await todoParser.parseTasks('/', contents); + const todo = todos[0]; + expect(todo.status).toEqual(TodoItemStatus.Todo); + expect(todo.actionDate).toBeUndefined(); + expect(todo.isSomedayMaybeNote).toEqual(true); +}); diff --git a/model/TodoParser.ts b/model/TodoParser.ts index 0d090f4..74ff949 100644 --- a/model/TodoParser.ts +++ b/model/TodoParser.ts @@ -23,15 +23,16 @@ export class TodoParser { const actionDate = this.parseDueDate(description, filePath); const descriptionWithoutDate = this.dateParser.removeDate(description); const somedayPattern = /#(someday)/g; + const isSomedayMaybeTask = description.match(somedayPattern) != null; return new TodoItem( status, descriptionWithoutDate, - description.match(somedayPattern) != null, + isSomedayMaybeTask, filePath, (entry.index ?? 0) + todoItemOffset, entry[0].length - todoItemOffset, - actionDate, + !isSomedayMaybeTask ? actionDate : undefined, ); }