Skip to content

Instantly share code, notes, and snippets.

@GitMurf
Last active June 20, 2021 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GitMurf/9b85fcc31f2f553365ca4765eb5dabb8 to your computer and use it in GitHub Desktop.
Save GitMurf/9b85fcc31f2f553365ca4765eb5dabb8 to your computer and use it in GitHub Desktop.
<%*
const dateFormat = "YYYY-MM-DD";
const dateBasisStr = await tp.system.prompt("When is the meeting?");
if (dateBasisStr) {
function createMessage(daysBefore, dateFormat, dateBasisStr) {
let parseResult;
let newDate;
let parseResultLink;
let nlDatesPlugin = app.plugins.getPlugin('nldates-obsidian');
parseResult = nlDatesPlugin.parseDate(dateBasisStr);
newDate = window.moment(parseResult.formattedString).add((daysBefore * -1), 'days').format(dateFormat);
if (newDate) {
if (newDate !== 'Invalid date') { parseResultLink = '[' + '[' + newDate + ']]'; }
}
if (parseResultLink) {
return parseResultLink;
} else {
return "";
}
}
let msgDate;
msgDate = createMessage(14, dateFormat, dateBasisStr);
tR += `Send agenda on ${msgDate}`
//Repeat to add multiple lines / dates
msgDate = createMessage(7, dateFormat, dateBasisStr);
tR += `\n`;
tR += `Send reminder on ${msgDate}`
msgDate = createMessage(1, dateFormat, dateBasisStr);
tR += `\n`;
tR += `Tomorrow is the meeting! ${msgDate} will remind me!`
}
%>
@kmaustral
Copy link

This is wonderful. I can see where it can be customised. The next challenge would be if you wanted to generate more than one line with different dates relative to the date basis.

@GitMurf
Copy link
Author

GitMurf commented Jun 9, 2021

The next challenge would be if you wanted to generate more than one line with different dates relative to the date basis.

@kmaustral I just updated the code to allow for adding multiple lines with different dates and messages. It uses a function now so can just repeat as few or many times as you want by copying these 3 lines and repeating:

//Repeat to add multiple lines / dates
msgDate = createMessage(7, dateFormat, dateBasisStr);
tR += `\n`;
tR += `Send reminder on ${msgDate}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment