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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
export async function bulletJournalMonth(month, year) {
const d = new Date();
let month2 = typeof month === "number" ? month : d.getMonth();
if (typeof year !== "undefined") {
d.setYear(year);
}
// NOTE: Add 1 here to set the date to the next month. Then, get the number of days for the
// original month.
d.setMonth(month2 + 1);
d.setDate(0);
const dm = d.getDate();
const half = Math.round(dm / 2);
// NOTE: Convert number of days into a list of weeks
let column = 0;
let copyOfDate = new Date(d.valueOf());
let pivot = half;
copyOfDate.setDate(half);
const halfDay = copyOfDate.getDay();
if (halfDay >= 3) {
pivot += 7 - halfDay;
} else {
pivot -= halfDay;
}
let md = `| | | | | |\n| --- | --- | --- | --- | --- |\n`;
let dt1 = pivot < 15 ? pivot - 14 : 1;
let dt2 = dt1 + 14;
while (true) {
if (dt1 >= pivot && dt2 > dm) {
break;
}
d.setDate(dt1);
if (dt1 === 1) {
d.setMonth(month2);
}
const wd = d.getDay();
let day = ["S", "M", "T", "W", "T", "F", "S"][wd];
const dt1Str = dt1 >= 1 && dt1 < pivot ? dt1 : "";
const dt2Str = dt2 >= pivot && dt2 <= dm ? dt2 : "";
md += `| \t |\t${dt1Str}\t| **${day}** |\t${dt2Str}\t| \t |\n`;
dt1 += 1;
dt2 += 1;
}
return md;
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.