1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export const everyMonday = (async () => {
// Prints every monday between 2 dates. I use it for quarterly planning.
// Outputs ready to paste in Notion as a bullet list
// --- Imports ---
const dateFns = await import("npm:date-fns");
const {
addDays,
startOfWeek,
startOfDay,
isSameDay,
isAfter,
isBefore,
format,
} = dateFns;
// --- Constants ---
// End of June
const from = new Date(2023, 5, 25);
// Beginning of October
const until = startOfDay(new Date(2023, 9, 1));
// --- Loop ---
let d = startOfWeek(from, { weekStartsOn: 1 });
const mondays: Date[] = [];
while (!isAfter(d, until)) {
if (!isBefore(d, from)) {
mondays.push(d);
}
d = startOfDay(addDays(d, 7));
}
// --- Format ---
return mondays.map((d) => format(d, "- MMM d")).join("\n\n");
})();
// Forked from @andreterron.everyMonday
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023