Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<%*
let dueDateStr = await tp.system.prompt("Enter Date", "Tomorrow");
let parseResult;
let parseResultLink;
let myString = '';
if(dueDateStr) {
let findDays = dueDateStr.split(';');
let myDateStr = findDays[0];
if(myDateStr) {
let nlDatesPlugin = this.app.plugins.getPlugin('nldates-obsidian');
parseResult = nlDatesPlugin.parseDate(myDateStr);
if(parseResult){parseResultLink = parseResult.formattedString;}
}
if(parseResultLink) {
const dnpStart = parseResult.date;
if(dnpStart) {
let daysInt = 0;
if(findDays.length > 1) {
daysInt = findDays[1];
}
let isNeg = false;
if(daysInt < 0){isNeg = true; daysInt = daysInt * -1;}
let dnp = '';
let dnp2 = '';
for (let i = 0; i <= daysInt; i++) {
let ctr = i;
if(isNeg && ctr > 0){ctr = ctr * -1}
let newDateVal = this.moment(dnpStart).add(ctr, 'days');
if(newDateVal) {
if(dnp !== ''){dnp += `|`}
dnp += newDateVal.format('YYYY-MM-DD');
if(dnp2 !== ''){dnp2 += `|`}
dnp2 += newDateVal.format('YYYY_MM_DD');
}
}
myString = `((file:/${dnp2}/ task-todo:"[ ]") OR ((/Due Date: .*\\[\\[(${dnp})\\]\\].*/ OR /due date: \\[[0-9, -]*(${dnp})[0-9, -]*\\]/) task-todo:"[ ]") OR (file:/${dnp}/ task-todo:"[ ]") OR (task-todo:/${dnp}/) OR section:(/^\#.*(${dnp})/ "[ ]") OR section:(/^\#.*(${dnp})/ section:("[ ]"))) -file:("weekly review")`;
}
}
}
if(myString !== '') {
const search = app.workspace.getLeavesOfType("search")[0];
search.view.setSortOrder("byCreatedTime");
search.view.setCollapseAll(false);
search.view.setExtraContext(true);
search.view.setQuery(`${myString}`);
app.workspace.revealLeaf(search);
}
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment