The basis of my daily routine is defined by tasks that repeat. For instance, I always read certain reports on Tuesdays. Furthermore, I have some tasks that need to be done on the last day of the month.
Sometimes, I may need to create a daily note far in advance, but it should have all of its tasks included so that when I get to it, I can do them.
Enter the templater plugin. I use the following code to insert the correct repeating tasks, regardless of when the note is created. I even have some tasks that I want to do on the last Thursday of the month, but only if the month will end on Friday, Saturday, or Sunday. this code handles that as well. Here it is:
<%*
const dayOfWeek = Number(tp.date.now("d", 0, tp.file.title, "YYYY.MM.DD"));
const dayOfMonth = Number(tp.date.now("D", 0, tp.file.title, "YYYY.MM.DD"));
const month = Number(tp.date.now("M", 0, tp.file.title, "YYYY.MM.DD"));
const year = Number(tp.date.now("YYYY", 0, tp.file.title, "YYYY.MM.DD"));
const lastDayOfMonth = Number(month === 2 ? ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0 ? 29 : 28) : [4, 6, 9, 11].includes(month) ? 30 : 31);
const doLastDOM = Boolean([1,2,3].includes(dayOfWeek) ? dayOfMonth === lastDayOfMonth : dayOfWeek == 4 ? dayOfMonth >= (lastDayOfMonth - 3) : false);
if (dayOfWeek == 1) {
// Monday
-%>
- [ ] first Monday task
- [ ] second Monday task
<%*
}
else if (dayOfWeek == 2) {
// Tuesday
-%>
- [ ] first Tuesday task
- [ ] second Tuesday task
<%*
}
else if (dayOfWeek == 3) {
// Wednesday
-%>
- [ ] first Wednesday task
- [ ] second Wednesday task
<%*
}
else if (dayOfWeek == 4) {
// Thursday
-%>
- [ ] first Thursday task
- [ ] second Thursday task
<%*
}
// End of Month Tasks
if (doLastDOM) {
-%>
- [ ] first End of Month task
- [ ] second End of Month task
<%*
}
-%>