Last active
January 15, 2024 15:50
-
-
Save TfTHacker/4e019abd25c58de57376add6e3aa4173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```dataviewjs | |
// find dates based on format [[YYYY-MM-DD]] | |
const findDated = (task)=>{ | |
if( !task.completed ) { | |
task.link = " " + "[[" + task.path + "|*]]"; | |
task.date=""; | |
const found = task.text.match(/\[\[([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))\]\]/); | |
if(found) task.date = moment(found[1]); | |
return true; | |
} | |
} | |
const myTasks = dv.pages("").file.tasks.where(t => findDated(t)); | |
dv.header(1,"Overdue"); | |
dv.table(["task","link"], myTasks.filter(t=> moment(t.date).isBefore(moment(),"day")).sort(t=>t.date).map(t=>[t.text, t.link])); | |
dv.header(1,"Today"); | |
dv.table(["task","link"], myTasks.filter(t=> moment(t.date).isSame(moment(),"day")).sort(t=>t.date).map(t=>[t.text, t.link])); | |
dv.header(1,"Upcoming"); | |
dv.table(["task","link"], myTasks.filter(t=> moment(t.date).isAfter(moment(),"day")).sort(t=>t.date).map(t=>[t.text, t.link])); | |
dv.header(1,"Undated"); | |
dv.table(["task","link"], myTasks.filter(t=> !t.date).sort(t=>t.text).map(t=>[t.text, t.link])); | |
``` |
Hey @creadian, what you are referring to is a comment. So this is just a description of what the code will do.
What you want to change is this:
const found = task.text.match(/[[([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))]]/);
That cryptic part is a regex, a pattern that it searches. You could try this (I've not tested that yet).
const found = task.text.match(/[[(((0[1-9]|[12]\d|3[01])-(0[1-9]|1[0-2])-[12]\d{3}))]]/);
I couldnt get that working, but const found = task.text.match(/([0-9]{2}-[0-9]{2}-[0-9]{4})/); like a charm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for the code- very useful. I have been using this on my daily note, but I would like to exclude tasks from "today's" note. My dailynotes are all named "YYYY-MM-DD" so I figured I just need to add in something like. dv.pages => ! "dv.current().date" ... but not too clued up on this yet