While we are here, here’s a script that (almost) abuses the awesome SpaceScript functionality to let you input dates in natural language
const chrono = import("https://esm.sh/[email protected]");
silverbullet.registerCommand({name:"Insert Date"}, async () => {
function pad(n) {
let s = String(n);
if (s.length === 1) {
s = "0" + s;
}
return s;
}
function datestr(d) {
return d.getFullYear() + "-" + (d.getMonth() + 1).toString().padStart(2, '0') + "-" + (d.getDate()).toString().padStart(2, '0');
}
async function dateparse(in_str) {
const { Chrono } = await chrono
const chrono_parser = new Chrono()
const result = chrono_parser.parseDate(in_str);
return datestr(result);
}
const input = await syscall("editor.prompt", "Insert a date in natural language", "")
if (input) {
const output = await dateparse(input);
await syscall("editor.insertAtCursor", output);
}
})