Skip to content

Commit

Permalink
Include someday/maybe tasks in daily notes in the someday/maybe list
Browse files Browse the repository at this point in the history
  • Loading branch information
larslockefeer committed Jan 19, 2022
1 parent a737d35 commit d865bac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion DemoVault/Daily Notes/2022-01-04.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
- [ ] Do something on this date
- [ ] Do something on this date
- [ ] Do something in 2099 [due:: 2099-01-01]
- [ ] Do something, some day #someday
26 changes: 26 additions & 0 deletions model/TodoParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
5 changes: 3 additions & 2 deletions model/TodoParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down

0 comments on commit d865bac

Please sign in to comment.