-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.js
80 lines (74 loc) · 2.09 KB
/
calendar.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var dayjs = require('dayjs');
function digits_count(n) {
let count = 0;
if (n >= 1) ++count;
while (n / 10 >= 1) {
n /= 10;
++count;
}
return count;
}
module.exports = function preview(document, date) {
document.fontSize(5);
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
let month = [
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
]
document.text(monthNames[date.month()],450,60);
console.log(date.month());
console.log(date.year());
let d = new Date(date.year(),date.month(),1)
let day = new dayjs(d);
console.log(day.day());
let dayNum = 0;
let monthWeek = 0;
for (let currentDate = day; currentDate.month() === day.month(); currentDate = currentDate.add(1, 'day')) {
month[monthWeek][currentDate.day()] = dayNum+1;
if(currentDate.day() === 6){
monthWeek++;
}
dayNum++;
}
/**
* Here all i had was document.text(month[week]) inside a for loop but rn I am trying to properly space the numbers
* based on the amount of digits.
*/
for(let week =0; week <7; week ++){
document.text(month[week]);
}
/**
for(let week = 0; week <= month.length; week++){
for(let i = 0; i < 7;i++){
if(digits_count(month[week][i]) > 1){
document.text(month[week][i] + " ")
}
else{
document.text(month[week][i] + " ")
}
}
}
**/
/**
monthWeek = 0;
for (let i = 0; i < 42; i++){
if ((i % 7 === 0) && (i !== 0)) {
monthWeek++;
console.log(month[monthWeek][i] + '\n');
}
else {
if(month[monthWeek][i].toString().length > 1){
console.log(month[monthWeek][i] + " ");
}
console.log(month[monthWeek][i] + " ");
}
}
**/
console.log(month);
}