-
Notifications
You must be signed in to change notification settings - Fork 1
/
text-calendar-4x3.html
180 lines (137 loc) Β· 9.21 KB
/
text-calendar-4x3.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>π
text-calendar | landscape</title>
</head>
<body>
<pre id="txt-cal"></pre>
<footer>
<p class="hint">Use your keyboard <kbd>β―</kbd> <kbd>β―</kbd> arrows to change year </p>
</footer>
<script>
// static variables
var norm_array = [
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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]
];
var leap_array = [
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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],
[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]
];
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var months_arrays = new Array(12);
// returns the text-calendar for the given year
function get_array_of_month( year, month ) {
var month_2D = new Array(6); // 5 "weeks" each of which will have an array of 7 "days"
var day = 0;
var week = 0;
var first_day_of_month = new Date(year, month, 1).getUTCDay(); // Monday is 0 / Sunday is 6
var calendar_array = (new Date(year, 1, 29).getMonth() == 1) ? leap_array : norm_array; // checks for leap year
// handle first day of the month
month_2D[0] = new Array(7);
for (i=0 ; i<first_day_of_month ; i++) {
month_2D[0][i] = " ";
}
for (i=first_day_of_month ; i<7 ; i++) {
month_2D[0][i] = calendar_array[0][day++].toString().padStart(3);
}
// continue with rest of the weeks (max is a month with 6 lines)
for (j=1 ; j<6 ; j++) {
month_2D[j] = new Array(7);
for (k=0 ; k<7 ; k++) {
if (day<calendar_array[month].length) {
month_2D[j][k] = calendar_array[month][day++].toString().padStart(3);
}
else {
month_2D[j][k] = " ";
}
}
}
return month_2D;
}
function get_text_calendar_landscape( year ) {
// iterate months
for (m=0 ; m<12 ; m++) {
months_arrays[m] = get_array_of_month(year_now, m);
}
var text_calendar_landscape = `βββββββββββββββββββββββββββββββββββββββββββββ `+ year +` ββββββββββββββββββββββββββββββββββββββββββββββ
January February March
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
`;
// 3 rows with 3 months each
for (w=0 ; w<6 ; w++) {
text_calendar_landscape += " " + months_arrays[0][w].join(" ") + " " + months_arrays[1][w].join(" ") + " " + months_arrays[2][w].join(" ") + " \n";
}
text_calendar_landscape +=`
April May June
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
`
// 3 rows with 3 months each
for (w=0 ; w<6 ; w++) {
text_calendar_landscape += " " + months_arrays[3][w].join(" ") + " " + months_arrays[4][w].join(" ") + " " + months_arrays[5][w].join(" ") + " \n";
}
text_calendar_landscape +=`
July August September
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
`
// 3 rows with 3 months each
for (w=0 ; w<6 ; w++) {
text_calendar_landscape += " " + months_arrays[6][w].join(" ") + " " + months_arrays[7][w].join(" ") + " " + months_arrays[8][w].join(" ") + " \n";
}
text_calendar_landscape +=`
October November December
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
`
// 3 rows with 3 months each
for (w=0 ; w<6 ; w++) {
text_calendar_landscape += " " + months_arrays[9][w].join(" ") + " " + months_arrays[10][w].join(" ") + " " + months_arrays[11][w].join(" ") + " \n";
}
return text_calendar_landscape;
}
// display current year text-calendar when page loads:
var year_now = new Date().getFullYear();
var year_now_text_landscape = get_text_calendar_landscape( year_now );
document.querySelector('#txt-cal').innerHTML = year_now_text_landscape;
// change year (next / previous) when the user presses (right / left) arrows
document.addEventListener('keydown', function(e) {
if ( event.keyCode == 37) {
year_now = year_now - 1;
document.querySelector('#txt-cal').innerHTML = get_text_calendar_landscape( year_now );
} else if ( event.keyCode == 39) {
year_now = year_now + 1;
document.querySelector('#txt-cal').innerHTML = get_text_calendar_landscape( year_now );
}
});
</script>
<style>
footer {font-family: sans-serif; font-size: 11px; color: #858585;}
footer a {color: #436f9d;}
</style>
</body>
</html>