ok, I came up with some javascript code that works but I can’t figure out how to use it in a macro or how to modify the “kit / code” so that I can write:
{{int [[Monday, 27.05.2024]], [[Monday, 03.06.2024]]}}
and it outputs:
[[Monday, 27.05.2024]] [[Tuesday, 28.05.2024]] [[Wednesday, 29.05.2024]] [[Thursday, 30.05.2024]] [[Friday, 31.05.2024]] [[Saturday, 01.06.2024]] [[Sunday, 02.06.2024]] [[Monday, 03.06.2024]]
This is the Logseq Page: “datesInterval”:
function convertToDateObject(dateString) {
// Strip the outer brackets from the dateString
const trimmedDateString = dateString.slice(2, -2);
// Extract day, date, month, and year from the trimmedDateString
const [, day, date, month, year] = trimmedDateString.match(/(\w+), (\d{2})\.(\d{2})\.(\d{4})/);
// Create a JavaScript Date object
const dateObj = new Date(`${month}/${date}/${year}`);
return dateObj;
}
function getAllDatesBetween(startDate, endDate) {
// Initialize an array to store all dates
const allDates = [];
// Set the start date as the current date
let currentDate = new Date(startDate);
// Loop until the current date is less than or equal to the end date
while (currentDate <= endDate) {
// Add the current date to the array
allDates.push(new Date(currentDate));
// Move to the next day
currentDate.setDate(currentDate.getDate() + 1);
}
return allDates;
}
function formatDateToLogseqJournalName(date) {
// Get the day of the week
const dayOfWeek = date.toLocaleDateString('en', { weekday: 'long' });
// Get the day, month, and year
const day = date.getDate().toString().padStart(2, '0');
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const year = date.getFullYear();
// Format the date string
return `[[${dayOfWeek}, ${day}.${month}.${year}]]`;
}
// const dateStr1 = "[[Monday, 27.05.2024]]";
// const dateStr2 = "[[Monday, 03.06.2024]]";
dateStr1 = $1
dateStr2 = $2
const dateObj1 = convertToDateObject(dateStr1);
const dateObj2 = convertToDateObject(dateStr2);
const allDates = getAllDatesBetween(dateObj1, dateObj2);
const formattedDates = allDates.map(date => formatDateToLogseqJournalName(date)).join(" ");
console.log(formattedDates);
I am trying to create the macro in config.edn
:
:int "<span class='kit' data-kit='datesInterval' ?? > ?? </span>"