Skip to content

Instantly share code, notes, and snippets.

@kumarchandresh
Created July 25, 2023 11:56
Show Gist options
  • Select an option

  • Save kumarchandresh/76c28991d19818c5dc57317ac524cf93 to your computer and use it in GitHub Desktop.

Select an option

Save kumarchandresh/76c28991d19818c5dc57317ac524cf93 to your computer and use it in GitHub Desktop.
function daily_calendar(tp) {
const lines = [];
lines.push("| SUN | MON | TUE | WED | THU | FRI | SAT |");
lines.push("| :---: | :---: | :---: | :---: | :---: | :---: | :---: |");
const now = tp.user.daily_note(tp);
const before = Array(now.date(1).weekday()).fill(0).map(() => " ");
const after = Array(6 - now.date(now.daysInMonth()).weekday()).fill(0).map(() => " ");
const during = Array(now.daysInMonth()).fill(0).map((_, i) => i + 1);
const calendar = [...before, ...during, ...after];
while (calendar.length) {
const week = calendar.splice(0, 7).map(d => {
const day = parseInt(d);
if (isNaN(day)) return " ";
return `[[${tp.user.daily_note.folder}/${now.date(day).format(tp.user.daily_note.format)}\\|${day}]]`;
}).join(" | ");
lines.push(`| ${week} |`);
};
return lines.join('\n');
}
module.exports = daily_calendar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment